Skip to content

Commit e492e6f

Browse files
committed
[FEATURE] Added benchmark results. Fixed #95 and Fixed #78
1 parent cb2071c commit e492e6f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

42PyChecker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def main():
5252
# @todo: Check what option is given based on the selected project.
5353
parser.add_argument("--no-required", help="Disables required functions check", action="store_true")
5454
parser.add_argument("--no-libft-unit-test", help="Disables libft-unit-test", action="store_true")
55-
# @todo: Fix --do-benchmark option for libft-unit-test
56-
parser.add_argument("--do-benchmark", help="Disables libft-unit-test benchmarking", action="store_false")
55+
parser.add_argument("--do-benchmark", help="Disables libft-unit-test benchmarking", action="store_true")
56+
5757

5858
# Calls the parser for the arguments we asked to implement.
5959
args = parser.parse_args()

PyChecker/projects/libft.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def check(root_path: str, args):
6565
bonus_functions = ['ft_lstnew.c', 'ft_lstdelone.c', 'ft_lstdel.c',
6666
'ft_lstiter.c', 'ft_lstadd.c', 'ft_lstmap.c']
6767
authorized_functions = ['free', 'malloc', 'write', 'main']
68-
# @todo: add libft-unit-test to the testing suite
6968
if not args.no_author:
7069
author_results = author.check(args.path)
7170
if not args.no_required:
@@ -88,7 +87,10 @@ def check(root_path: str, args):
8887
if not args.no_maintest:
8988
maintest_ok, maintest_fail = maintest.run_libft(args.path, root_path)
9089
if not args.no_libft_unit_test:
91-
libft_unit_test_results = libft_unit_test.run(root_path, args)
90+
if args.do_benchmark:
91+
libft_unit_test_results, benchmark_results = libft_unit_test.run(root_path, args)
92+
else:
93+
libft_unit_test_results = libft_unit_test.run(root_path, args)
9294
print("\n\n\nThe results are in:\n")
9395
if not args.no_author:
9496
print("Author File: \n" + author_results + '\n')
@@ -115,5 +117,9 @@ def check(root_path: str, args):
115117
if not args.no_maintest:
116118
print("Maintest: \n{} OKs and {} FAILs.".format(maintest_ok, maintest_fail))
117119
if not args.no_libft_unit_test:
118-
print('libft-unit-test: \n' + libft_unit_test_results)
120+
if args.do_benchmark:
121+
# @todo: Strip useless chars from benchmark results
122+
print('libft-unit-test: \n' + libft_unit_test_results + '\n\n' + benchmark_results)
123+
else:
124+
print('libft-unit-test: \n' + libft_unit_test_results)
119125
return 0

PyChecker/testing_suite/libft_unit_test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@ def run(root_path: str, args):
1919
file.write("Sorry, this testing suite can only be ran on Darwin computers (MacOS)\n")
2020
return "Sorry, this testing suite can only be ran on Darwin computers (MacOS)"
2121
with open(root_path + '/.mylibftunittest', 'w+') as file:
22-
result = subprocess.run(['make', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
22+
result = subprocess.run(['make', 're', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
2323
file.write(result)
2424
print(result)
2525
result = subprocess.run(['make', 'f', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
2626
print(result)
2727
file.write(result)
2828
os.rename(root_path + '/testing_suites/libft-unit-test/result.log', root_path + '/.mylibftunittest-results')
2929
if args.do_benchmark:
30-
result = subprocess.run([root_path + '/testing_suites/libft-unit-test/run_test', '-b'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
30+
oldpwd = os.getcwd()
31+
os.chdir(root_path + '/testing_suites/libft-unit-test/')
32+
result = subprocess.run(['./run_test', '-b'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
33+
os.chdir(oldpwd)
3134
print(result)
3235
file.write(result)
33-
# @todo: return results from benchmark
36+
with open(root_path + '/.mylibftunittest', 'r') as file2:
37+
for line in file2:
38+
if "WINNER:" in line:
39+
benchmark_results = line
3440
with io.open(root_path + '/.mylibftunittest-results', "r", encoding="ISO-8859-1") as file:
3541
data = file.read()
3642
results = 'OKs: ' + str(data.count('OK')) + '\n'
@@ -40,4 +46,7 @@ def run(root_path: str, args):
4046
results += 'protected: ' + str(data.count('protected')) + '\n'
4147
results += 'not protected:' + str(data.count('not protected'))
4248
print(results)
43-
return results
49+
if args.do_benchmark:
50+
return results, benchmark_results
51+
else:
52+
return results

0 commit comments

Comments
 (0)