1+ #!/usr/bin/env python3
2+ # Copyright (C) 2016 Fan Long, Martin Rianrd and MIT CSAIL
3+ # Prophet
4+ #
5+ # This file is part of Prophet.
6+ #
7+ # Prophet is free software: you can redistribute it and/or modify
8+ # it under the terms of the GNU General Public License as published by
9+ # the Free Software Foundation, either version 3 of the License, or
10+ # (at your option) any later version.
11+ #
12+ # Prophet is distributed in the hope that it will be useful,
13+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ # GNU General Public License for more details.
16+ #
17+ # You should have received a copy of the GNU General Public License
18+ # along with Prophet. If not, see <http://www.gnu.org/licenses/>.
19+ from sys import argv
20+ from os import system ,mkdir ,chdir ,getcwd
21+ import getopt
22+ import shutil
23+ import subprocess
24+
25+ if __name__ == "__main__" :
26+ if len (argv ) < 4 :
27+ print ("Usage: php-tester.py <src_dir> <test_dir> <work_dir> [cases]" )
28+ exit (1 );
29+
30+ opts , args = getopt .getopt (argv [1 :], "p:i:" );
31+ profile_dir = "" ;
32+ temp_dir = "__temp_test"
33+ for o , a in opts :
34+ if o == "-p" :
35+ profile_dir = a ;
36+ elif o == '-i' :
37+ temp_dir = a
38+
39+ mkdir (temp_dir );
40+ orig_dir = getcwd ()
41+ chdir (temp_dir )
42+
43+
44+ src_dir = args [0 ];
45+ test_dir = args [1 ];
46+ work_dir = args [2 ];
47+ if profile_dir == "" :
48+ cur_dir = src_dir ;
49+ else :
50+ cur_dir = profile_dir ;
51+
52+ if len (args ) > 3 :
53+ ids = args [3 :];
54+ for i in ids :
55+ shutil .copyfile (test_dir + "/" + str (i ) + ".in" , "./" + str (i ) + ".in" )
56+ shutil .copyfile (test_dir + "/" + str (i ) + ".exp" , "./" + str (i ) + ".exp" )
57+
58+ proc = subprocess .Popen ([cur_dir + "/prog" ], stdout = subprocess .PIPE ,stdin = subprocess .PIPE )
59+ if (i != "0" ):
60+ with open (str (i ) + ".in" , "r" ) as f :
61+ stdin = f .read ()
62+ output ,_ = proc .communicate (input = stdin .encode ('utf-8' ))
63+ else :
64+ output ,_ = proc .communicate ()
65+ with open ("__out" , "w" ) as f :
66+ f .write (output .decode ("utf-8" ))
67+
68+ ret = proc .returncode
69+ if (ret == 0 ):
70+ cmd = "diff __out " + test_dir + "/" + i + ".exp 1> /dev/null"
71+ ret = system (cmd )
72+ if (ret == 0 ):
73+ print (i )
74+ # system("rm -rf __out");
75+ print ()
76+
77+ chdir (orig_dir )
78+ # shutil.rmtree(temp_dir)
79+ system ('rm -rf ' + temp_dir )
0 commit comments