From 12afc6633e0c91ed2d635ae14fd1b72a0ce26e9c Mon Sep 17 00:00:00 2001 From: Erki Date: Sat, 18 Jun 2022 11:26:42 +0300 Subject: [PATCH] Okay maybe? --- .drone.yml | 4 +- op-summarizer/data/gcov.json | 53 +++++++ op-summarizer/data/opfinder.json | 213 +++++++++++++++++++++++++++ op-summarizer/opsummarizer.py | 61 +++++++- op-summarizer/tests.py | 10 +- testcases/Dhrystone.c | 235 ++++++++++++++++++++++++++++++ testcases/Whetstone.c | 241 +++++++++++++++++++++++++++++++ testcases/if_sentences.c | 54 +++++++ testcases/matrix.c | 6 +- 9 files changed, 862 insertions(+), 15 deletions(-) create mode 100644 op-summarizer/data/gcov.json create mode 100644 op-summarizer/data/opfinder.json create mode 100644 testcases/Dhrystone.c create mode 100644 testcases/Whetstone.c create mode 100644 testcases/if_sentences.c diff --git a/.drone.yml b/.drone.yml index 4553806..b53f13a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -29,8 +29,8 @@ steps: - cd build - conan install .. --build=missing - cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=OFF - - ninja + - ninja op-finder - cp -r ../testcases ./testcases - cd ./testcases - - mv ../op-finder ./ + - ln ../op-finder/op-finder ./op-finder - python3 ../../op-summarizer/tests.py diff --git a/op-summarizer/data/gcov.json b/op-summarizer/data/gcov.json new file mode 100644 index 0000000..c14613a --- /dev/null +++ b/op-summarizer/data/gcov.json @@ -0,0 +1,53 @@ +{"files": [{"file": "gauss_blur.c", "lines": [ + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 1}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 3}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 4}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 5}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 6}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 7}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 8}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 9}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 11}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 12}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 13}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 18}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 19}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 20}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 21}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 22}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 23}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 24}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 26}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 27}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 28}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 29}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 30}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 31}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 32}, {"branches": [{"count": 2500, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 2501, "gcovr/noncode": false, "line_number": 33}, {"branches": [], "count": 2500, "gcovr/noncode": false, "line_number": 34}, {"branches": [], "count": 2500, "gcovr/noncode": false, "line_number": 35}, {"branches": [{"count": 9, "fallthrough": true, "throw": false}, {"count": 2491, "fallthrough": false, "throw": false}], "count": 2500, "gcovr/noncode": false, "line_number": 36}, {"branches": [], "count": 9, "gcovr/noncode": false, "line_number": 37}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 38}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 39}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 40}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 41}, {"branches": [{"count": 50, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 51, "gcovr/noncode": false, "line_number": 42}, {"branches": [], "count": 50, "gcovr/noncode": false, "line_number": 43}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 44}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 45}, {"branches": [{"count": 3, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 4, "gcovr/noncode": false, "line_number": 46}, {"branches": [], "count": 3, "gcovr/noncode": false, "line_number": 47}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 48}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 49}, {"branches": [{"count": 50, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 51, "gcovr/noncode": false, "line_number": 52}, {"branches": [{"count": 2500, "fallthrough": false, "throw": false}, {"count": 50, "fallthrough": true, "throw": false}], "count": 2550, "gcovr/noncode": false, "line_number": 53}, {"branches": [], "count": 2500, "gcovr/noncode": false, "line_number": 54}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 55}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 56}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 57}, {"branches": [{"count": 48, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 49, "gcovr/noncode": false, "line_number": 58}, {"branches": [{"count": 2304, "fallthrough": false, "throw": false}, {"count": 48, "fallthrough": true, "throw": false}], "count": 2352, "gcovr/noncode": false, "line_number": 59}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 60}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 61}, {"branches": [{"count": 6912, "fallthrough": false, "throw": false}, {"count": 2304, "fallthrough": true, "throw": false}], "count": 9216, "gcovr/noncode": false, "line_number": 62}, {"branches": [], "count": 6912, "gcovr/noncode": false, "line_number": 63}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 64}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 65}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 66}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 67}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 68}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 69}, {"branches": [{"count": 2500, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 2501, "gcovr/noncode": false, "line_number": 70}, {"branches": [], "count": 2500, "gcovr/noncode": false, "line_number": 71}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 72}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 73}, {"branches": [{"count": 48, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 49, "gcovr/noncode": false, "line_number": 74}, {"branches": [{"count": 2304, "fallthrough": false, "throw": false}, {"count": 48, "fallthrough": true, "throw": false}], "count": 2352, "gcovr/noncode": false, "line_number": 75}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 76}, {"branches": [{"count": 4608, "fallthrough": false, "throw": false}, {"count": 2304, "fallthrough": true, "throw": false}], "count": 6912, "gcovr/noncode": false, "line_number": 77}, {"branches": [], "count": 4608, "gcovr/noncode": false, "line_number": 78}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 79}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 80}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 81}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 82}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 83}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 84}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 85}, {"branches": [{"count": 2500, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 2501, "gcovr/noncode": false, "line_number": 86}, {"branches": [], "count": 2500, "gcovr/noncode": false, "line_number": 87}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 88}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 89}, {"branches": [{"count": 48, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 49, "gcovr/noncode": false, "line_number": 90}, {"branches": [{"count": 2304, "fallthrough": false, "throw": false}, {"count": 48, "fallthrough": true, "throw": false}], "count": 2352, "gcovr/noncode": false, "line_number": 91}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 92}, {"branches": [{"count": 6912, "fallthrough": false, "throw": false}, {"count": 2304, "fallthrough": true, "throw": false}], "count": 9216, "gcovr/noncode": false, "line_number": 93}, {"branches": [{"count": 20736, "fallthrough": false, "throw": false}, {"count": 6912, "fallthrough": true, "throw": false}], "count": 27648, "gcovr/noncode": false, "line_number": 94}, {"branches": [{"count": 6912, "fallthrough": true, "throw": false}, {"count": 13824, "fallthrough": false, "throw": false}, {"count": 4608, "fallthrough": true, "throw": false}, {"count": 2304, "fallthrough": false, "throw": false}], "count": 20736, "gcovr/noncode": false, "line_number": 95}, {"branches": [], "count": 18432, "gcovr/noncode": false, "line_number": 96}, {"branches": [], "count": 18432, "gcovr/noncode": false, "line_number": 97}, {"branches": [{"count": 4340, "fallthrough": true, "throw": false}, {"count": 14092, "fallthrough": false, "throw": false}], "count": 18432, "gcovr/noncode": false, "line_number": 98}, {"branches": [], "count": 4340, "gcovr/noncode": false, "line_number": 99}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 100}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 101}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 102}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 103}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 104}, {"branches": [], "count": 2304, "gcovr/noncode": false, "line_number": 105}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 106}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 107}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 108}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 110}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 111}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 112}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 113}, {"branches": [{"count": 50, "fallthrough": false, "throw": false}, {"count": 1, "fallthrough": true, "throw": false}], "count": 51, "gcovr/noncode": false, "line_number": 114}, {"branches": [], "count": 50, "gcovr/noncode": false, "line_number": 115}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 116}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 117}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 118}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 119}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 120}, {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 121}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 122}, {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 123}]}, + {"file": "matrix.c", "lines": [ + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 2}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 8}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 15}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 16}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 17}, + {"branches": [ + {"count": 3, "fallthrough": false, "throw": false}, + {"count": 1, "fallthrough": true, "throw": false} + ], "count": 4, "gcovr/noncode": false, "line_number": 20}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 21}, + {"branches": [ + {"count": 15, "fallthrough": false, "throw": false}, + {"count": 3, "fallthrough": true, "throw": false} + ], "count": 18, "gcovr/noncode": false, "line_number": 22}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 23}, + {"branches": [], "count": 15, "gcovr/noncode": false, "line_number": 24}, + {"branches": [ + {"count": 60, "fallthrough": false, "throw": false}, + {"count": 15, "fallthrough": true, "throw": false} + ], "count": 75, "gcovr/noncode": false, "line_number": 25}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 26}, + {"branches": [], "count": 60, "gcovr/noncode": false, "line_number": 27}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 28}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 29}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 30}, + {"branches": [], "count": 1, "gcovr/noncode": false, "line_number": 31}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 32}, + {"branches": [], "count": 0, "gcovr/noncode": true, "line_number": 33} + ]}], "gcovr/format_version": 0.1} \ No newline at end of file diff --git a/op-summarizer/data/opfinder.json b/op-summarizer/data/opfinder.json new file mode 100644 index 0000000..db3d46f --- /dev/null +++ b/op-summarizer/data/opfinder.json @@ -0,0 +1,213 @@ +{ + "matrix.c": [ + { + "branch_number": 1, + "entry": { + "operation_name": "=", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 20 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "<", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 20 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "++", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "" + }, + "entry_type": "basic_operation", + "line": 20 + }, + { + "branch_number": 1, + "entry": { + "operation_name": "=", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 22 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "<", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 22 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "++", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "" + }, + "entry_type": "basic_operation", + "line": 22 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "=", + "type_lhs": "unsigned short", + "type_result": "unsigned short", + "type_rhs": "unsigned short" + }, + "entry_type": "basic_operation", + "line": 24 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "volatile UInt16 *", + "type_result": "unsigned short", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 24 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "volatile UInt16 (*)[5]", + "type_result": "volatile UInt16 [5]", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 24 + }, + { + "branch_number": 1, + "entry": { + "operation_name": "=", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 25 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "<", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 25 + }, + { + "branch_number": 2, + "entry": { + "operation_name": "++", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "" + }, + "entry_type": "basic_operation", + "line": 25 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "volatile UInt16 *", + "type_result": "unsigned short", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "volatile UInt16 (*)[5]", + "type_result": "volatile UInt16 [5]", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "*", + "type_lhs": "int", + "type_result": "int", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "const UInt16 *", + "type_result": "unsigned short", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "const UInt16 (*)[4]", + "type_result": "const UInt16 [4]", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "const UInt16 *", + "type_result": "unsigned short", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + }, + { + "branch_number": 0, + "entry": { + "operation_name": "subscript", + "type_lhs": "const UInt16 (*)[5]", + "type_result": "const UInt16 [5]", + "type_rhs": "int" + }, + "entry_type": "basic_operation", + "line": 27 + } + ] +} \ No newline at end of file diff --git a/op-summarizer/opsummarizer.py b/op-summarizer/opsummarizer.py index 1d22be7..e5b585f 100644 --- a/op-summarizer/opsummarizer.py +++ b/op-summarizer/opsummarizer.py @@ -1,10 +1,10 @@ import json from dataclasses import asdict -from typing import Dict, List +from typing import Dict, List, Tuple from gcovreader import GCovFile -from opfinderreader import OperationLogReader, UniqueOperation +from opfinderreader import OperationLogReader, UniqueOperation, OperationLog class OpSummarizer: @@ -15,6 +15,25 @@ class OpSummarizer: self.gcov.read() self.ops.read() + self.model: Dict[UniqueOperation, Tuple[float, float]] = None + self.uncounted_estimates: Dict[UniqueOperation, int] = {} + self.energy_consumption_estimation = 0.0 + self.execution_time_estimation = 0.0 + + def add_model(self, model_path: str) -> None: + with open(model_path, "r") as model_file: + data = json.load(model_file) + + assert type(data) == list, "Model file did not contain a JSON list." + + self.model = {} + for entry in data: + unique_op = OperationLog(**entry["unique_operation"]).entry + energy = entry["energy_consumption"] + time = entry["execution_time"] + + self.model[unique_op] = [energy, time] + def count_operations(self, file: str) -> Dict[UniqueOperation, int]: if file not in self.gcov.files or file not in self.ops.files: print(f"Gcov files: {self.gcov.files.keys()}") @@ -40,6 +59,18 @@ class OpSummarizer: return op_counter + def update_estimations(self, uops: Dict[UniqueOperation, int]) -> None: + assert self.model, "Model not populated." + for unique_op, op_count in uops.items(): + if unique_op in self.model: + energy, time = self.model[unique_op] + self.energy_consumption_estimation += energy * op_count + self.execution_time_estimation += time * op_count + elif unique_op in self.uncounted_estimates: + self.uncounted_estimates[unique_op] += op_count + else: + self.uncounted_estimates[unique_op] = op_count + @staticmethod def operation_count_to_json_dict(unique_ops: Dict[UniqueOperation, int]) -> List[Dict]: out = [] @@ -64,16 +95,24 @@ if __name__ == "__main__": help="The op-finder json file to use.") parser.add_argument("--output", type=str, default=None, required=False, help="The file to output the data to.") + parser.add_argument("--model", type=str, default=None, required=False, + help="The JSON file containing the system model.") args = parser.parse_args() summarizer = OpSummarizer(args.gcov, args.finder) - total_count = {} + if args.model: + summarizer.add_model(args.model) + + uops_dictionary = {} total_num = 0 for file_name in args.files: ops = summarizer.count_operations(file_name) - total_count[file_name] = summarizer.operation_count_to_json_dict(ops) + uops_dictionary[file_name] = summarizer.operation_count_to_json_dict(ops) + + if args.model: + summarizer.update_estimations(ops) print(f"Unique operations for file {file_name}:") for uop, count in ops.items(): @@ -86,4 +125,16 @@ if __name__ == "__main__": if args.output: with open(args.output, "w") as outfile: - json.dump(total_count, outfile) + json.dump(uops_dictionary, outfile) + + if args.model: + power_usage_estimate = summarizer.energy_consumption_estimation + time_estimate = summarizer.execution_time_estimation + print("---------") + print(f"Total energy usage estimation: {power_usage_estimate} mJ\nTotal execution time estimation: {time_estimate} ms") + if summarizer.uncounted_estimates: + print("Operations not accounted for (missing from the model):") + for uop, count in summarizer.uncounted_estimates.items(): + print(f"\t{uop}: {count}") + else: + print("No operations missing from the model.") diff --git a/op-summarizer/tests.py b/op-summarizer/tests.py index cbf7bee..d118445 100644 --- a/op-summarizer/tests.py +++ b/op-summarizer/tests.py @@ -12,8 +12,8 @@ from opsummarizer import OpSummarizer class Compiler: def __init__(self, root_file: str) -> None: self.root_file = root_file - self.gcov_file = f"{root_file}_gcov.json" - self.opfinder_file = f"{root_file}_opfinder.json" + self.gcov_file = f"./{root_file}_gcov.json" + self.opfinder_file = f"./{root_file}_opfinder.json" def compile_and_profile(self) -> None: output_file = f"{self.root_file}.out" @@ -69,8 +69,8 @@ if __name__ == "__main__": suite = unittest.TestSuite() suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "matrix")) - suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "gauss_blur")) - suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "for_loop")) - suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "fir")) + # suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "gauss_blur")) + # suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "for_loop")) + # suite.addTest(SummarizerCreatesExpectedOutput("test_summarizer_output", "fir")) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/testcases/Dhrystone.c b/testcases/Dhrystone.c new file mode 100644 index 0000000..8114ba6 --- /dev/null +++ b/testcases/Dhrystone.c @@ -0,0 +1,235 @@ +/******************************************************************************* + * + * Name : Dhrystone + * Purpose : Benchmark the Dhrystone code. This benchmark is used to gauge + * the performance of the microcontroller in handling pointers, + * structures and strings. + * + *******************************************************************************/ +#include +#include + +#define LOOPS 100 /* Use this for slow or 16 bit machines */ +#define structassign(d, s) d = s +typedef enum { + Ident1, Ident2, Ident3, Ident4, Ident5 +} Enumeration; +typedef int OneToThirty; +typedef int OneToFifty; +typedef unsigned char CapitalLetter; +typedef unsigned char String30[31]; +typedef int Array1Dim[51]; +typedef int Array2Dim[10][10]; +struct Record +{ + struct Record *PtrComp; + Enumeration Discr; + Enumeration EnumComp; + OneToFifty IntComp; + String30 StringComp; +}; +typedef struct Record RecordType; +typedef RecordType * RecordPtr; +typedef int boolean; +//#define NULL 0 +#define TRUE 1 +#define FALSE 0 +#define REG register +int IntGlob; +boolean BoolGlob; +unsigned char Char1Glob; +unsigned char Char2Glob; +Array1Dim Array1Glob; +Array2Dim Array2Glob; +RecordPtr PtrGlb; +RecordPtr PtrGlbNext; +RecordType rec1, rec2; +Enumeration Func1(CapitalLetter CharPar1, CapitalLetter CharPar2) { + REG CapitalLetter CharLoc1; + REG CapitalLetter CharLoc2; + CharLoc1 = CharPar1; + CharLoc2 = CharLoc1; + if (CharLoc2 != CharPar2) + return (Ident1); + else + return (Ident2); +} +boolean Func2(String30 StrParI1, String30 StrParI2) { + REG OneToThirty IntLoc; + REG CapitalLetter CharLoc; + IntLoc = 1; + while (IntLoc <= 1) + if (Func1(StrParI1[IntLoc], StrParI2[IntLoc + 1]) == Ident1) { + CharLoc = 'A'; + ++IntLoc; + } + if (CharLoc >= 'W' && CharLoc <= 'Z') + IntLoc = 7; + if (CharLoc == 'X') + return (TRUE); + else { + if (strcmp(StrParI1, StrParI2) > 0) { + IntLoc += 7; + return (TRUE); + } else + return (FALSE); + } +} +boolean Func3(Enumeration EnumParIn) { + REG Enumeration EnumLoc; + EnumLoc = EnumParIn; + if (EnumLoc == Ident3) + return (TRUE); + return (FALSE); +} +void Proc7(OneToFifty IntParI1, OneToFifty IntParI2, OneToFifty *IntParOut) { + REG OneToFifty IntLoc; + IntLoc = IntParI1 + 2; + *IntParOut = IntParI2 + IntLoc; +} +void Proc4(void) { + REG boolean BoolLoc; + BoolLoc = Char1Glob == 'A'; + BoolLoc |= BoolGlob; + Char2Glob = 'B'; +} +void Proc5(void) { + Char1Glob = 'A'; + BoolGlob = FALSE; +} +void Proc6(Enumeration EnumParIn, Enumeration *EnumParOut) { + *EnumParOut = EnumParIn; + if (!Func3(EnumParIn)) + *EnumParOut = Ident4; + switch (EnumParIn) { + case Ident1: + *EnumParOut = Ident1; + break; + case Ident2: + if (IntGlob > 100) + *EnumParOut = Ident1; + else + *EnumParOut = Ident4; + break; + case Ident3: + *EnumParOut = Ident2; + break; + case Ident4: + break; + case Ident5: + *EnumParOut = Ident3; + } +} +void Proc3(RecordPtr *PtrParOut) { + if (PtrGlb != NULL) + *PtrParOut = PtrGlb->PtrComp; + else + IntGlob = 100; + Proc7(10, IntGlob, &PtrGlb->IntComp); +} +void Proc1(RecordPtr PtrParIn) { +#define NextRecord (*(PtrParIn->PtrComp)) + structassign(NextRecord, *PtrGlb); + PtrParIn->IntComp = 5; + NextRecord.IntComp = PtrParIn->IntComp; + NextRecord.PtrComp = PtrParIn->PtrComp; + Proc3(&NextRecord.PtrComp); + if (NextRecord.Discr == Ident1) { + NextRecord.IntComp = 6; + Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp); + NextRecord.PtrComp = PtrGlb->PtrComp; + Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp); + } else + structassign(*PtrParIn, NextRecord); +#undef NextRecord +} +void Proc2(OneToFifty *IntParIO) { + REG OneToFifty IntLoc; + REG Enumeration EnumLoc; + IntLoc = *IntParIO + 10; + for (;;) { + if (Char1Glob == 'A') { + --IntLoc; + *IntParIO = IntLoc - IntGlob; + EnumLoc = Ident1; + } + if (EnumLoc == Ident1) + break; + } +} +void Proc8(Array1Dim Array1Par, Array2Dim Array2Par, OneToFifty IntParI1, + OneToFifty IntParI2) { + REG OneToFifty IntLoc; + REG OneToFifty IntIndex; + IntLoc = IntParI1 + 5; + Array1Par[IntLoc] = IntParI2; + Array1Par[IntLoc + 1] = Array1Par[IntLoc]; + Array1Par[IntLoc + 30] = IntLoc; + for (IntIndex = IntLoc; IntIndex <= (IntLoc + 1); ++IntIndex) + Array2Par[IntLoc][IntIndex] = IntLoc; + ++Array2Par[IntLoc][IntLoc - 1]; + Array2Par[IntLoc + 20][IntLoc] = Array1Par[IntLoc]; + IntGlob = 5; +} +void Proc0(void) { + OneToFifty IntLoc1; + REG OneToFifty IntLoc2; + OneToFifty IntLoc3; + REG unsigned char CharLoc; + REG unsigned char CharIndex; + Enumeration EnumLoc; + String30 String1Loc; + String30 String2Loc; + //extern unsigned char *malloc(); + long time(long *); + long starttime; + long benchtime; + long nulltime; + register unsigned int i; + for (i = 0; i < LOOPS; ++i) + ; + PtrGlbNext = &rec1; /* (RecordPtr) malloc(sizeof(RecordType)); */ + PtrGlb = &rec2; /* (RecordPtr) malloc(sizeof(RecordType)); */ + PtrGlb->PtrComp = PtrGlbNext; + PtrGlb->Discr = Ident1; + PtrGlb->EnumComp = Ident3; + PtrGlb->IntComp = 40; + strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING"); + strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); /*GOOF*/ + Array2Glob[8][7] = 10; /* Was missing in published program */ + for (i = 0; i < LOOPS; ++i) { + Proc5(); + Proc4(); + IntLoc1 = 2; + IntLoc2 = 3; + strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); + EnumLoc = Ident2; + BoolGlob = !Func2(String1Loc, String2Loc); + while (IntLoc1 < IntLoc2) { + IntLoc3 = 5 * IntLoc1 - IntLoc2; + Proc7(IntLoc1, IntLoc2, &IntLoc3); + ++IntLoc1; + } + Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3); + Proc1(PtrGlb); + for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex) + if (EnumLoc == Func1(CharIndex, 'C')) + Proc6(Ident1, &EnumLoc); + IntLoc3 = IntLoc2 * IntLoc1; + IntLoc2 = IntLoc3 / IntLoc1; + IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1; + Proc2(&IntLoc1); + } +} +int main(void) { + // TRISG = 0; + //PORTG = 0; + int i; + //while(1){ + // LATGINV = 0x0001; + for(i = 0; i < 100; i++){ + Proc0(); + } + //} + +} diff --git a/testcases/Whetstone.c b/testcases/Whetstone.c new file mode 100644 index 0000000..7607e40 --- /dev/null +++ b/testcases/Whetstone.c @@ -0,0 +1,241 @@ +/*************************************************************************** +* +* Name : Whetstone +* Purpose : Benchmark the Whetstone code. The code focuses on scientific +* functions such as sine, cosine, exponents and logarithm on +* fixed and floating point numbers. +* +***************************************************************************/ +/* List of changes (since TI slaa205b.pdf): + - void type of PA(), P0(), P3() + - dummy functions to prevent optimization + - float (not double) variants of math funcions and constants (this + is no matter for AVR) + */ + +#include + + +#ifdef __AVR__ +# define atanf(x) atan(x) +# define cosf(x) cos(x) +# define expf(x) exp(x) +# define logf(x) log(x) +# define sinf(x) sin(x) +# define sqrtf(x) sqrt(x) +#endif + +/* Extern functions. To prevent compiler's optimization. */ +void dummy1 (float x ){} +void dummy2 (float x , float y){} + +void PA (float E[5]); +void P0 (void); +void P3 (float *X, float *Y, float *Z); + +float T, T1, T2, E1[5]; +int J, K, L; +float X1, X2, X3, X4; +long ptime, time0; + +int main() +{ + //TRISG = 0; + //PORTG = 0; + int i; + //while(1){ + //LATGINV = 0x0001; + for(i = 0; i < 100; i++){ + + int LOOP, I, II, JJ, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11; + float X, Y, Z; + T = .499975; + T1 = 0.50025; + T2 = 2.0; + LOOP = 1; + II = 1; + + for (JJ = 1; JJ <= II; JJ++) { + N1 = 0; + N2 = 2 * LOOP; + N3 = 2 * LOOP; + N4 = 2 * LOOP; + N5 = 0; + N6 = 2 * LOOP; + N7 = 2 * LOOP; + N8 = 2 * LOOP; + N9 = 2 * LOOP; + N10 = 0; + N11 = 2 * LOOP; + + /* Module 1: Simple identifiers */ + X1 = 1.0; + X2 = -1.0; + X3 = -1.0; + X4 = -1.0; + if (N1 != 0) { + for (I = 1; I <= N1; I++) { + X1 = (X1 + X2 + X3 - X4) * T; + X2 = (X1 + X2 - X3 + X4) * T; + X3 = (X1 - X2 + X3 + X4) * T; + X4 = (-X1 + X2 + X3 + X4) * T; + } + } + + /* Module 2: Array elements */ + E1[1] = 1.0; + E1[2] = -1.0; + E1[3] = -1.0; + E1[4] = -1.0; + if (N2 != 0) { + for (I = 1; I <= N2; I++) { + E1[1] = (E1[1] + E1[2] + E1[3] - E1[4]) * T; + E1[2] = (E1[1] + E1[2] - E1[3] + E1[4]) * T; + E1[3] = (E1[1] - E1[2] + E1[3] + E1[4]) * T; + E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T; + } + } + + /* Module 3: Array as parameter */ + if (N3 != 0) { + for (I = 1; I <= N3; I++) { + PA (E1); + } + } + + /* Module 4: Conditional jumps */ + J = 1; + if (N4 != 0) { + for (I = 1; I <= N4; I++) { + if (J == 1) + goto L51; + J = 3; + goto L52; + L51: + J = 2; + L52: + if (J > 2) + goto L53; + J = 1; + goto L54; + L53: + J = 0; + L54: + if (J < 1) + goto L55; + J = 0; + goto L60; + L55: + J = 1; + L60: ; + } + } + + /* Module 5: Integer arithmetic */ + J = 1; + K = 2; + L = 3; + if (N6 != 0) { /* ??? Where is N5? */ + for (I = 1; I <= N6; I++) { + J = J * (K - J) * (L - K); + K = L * K - (L - J) * K; + L = (L - K) * (K + J); + E1[L - 1] = J + K + L; + E1[K - 1] = J * K * L; + } + } + + /* Module 6: Trigonometric functions */ + X = 0.5; + Y = 0.5; + if (N7 != 0) { + for (I = 1; I <= N7; I++) { + X = T * atanf (T2 * sinf (X) * cosf (X) / + (cosf (X + Y) + cosf (X - Y) - 1.0f)); + Y = T * atanf (T2 * sinf (Y) * cosf (Y) / + (cosf (X + Y) + cosf (X - Y) - 1.0f)); + } + } + dummy2 (X, Y); + + /* Module 7: Procedure calls */ + X = 1.0; + Y = 1.0; + Z = 1.0; + if (N8 != 0) { + for (I = 1; I <= N8; I++) { + P3 (&X, &Y, &Z); + } + } + + /* Module 8: Array references */ + J = 1; + K = 2; + L = 3; + E1[1] = 1.0; + E1[2] = 2.0; + E1[3] = 3.0; + if (N9 != 0) { + for (I = 1; I <= N9; I++) { + P0 (); + } + } + + /* Module 9: Integer arithmetic */ + J = 2; + K = 3; + if (N10 != 0) { /* TI skips this strange test. */ + for (I = 1; I <= N10; I++) { + J = J + K; + K = J + K; + J = K - J; + K = K - J - J; + } + } + + /* Module 10: Standard functions */ + X = 0.75; + if (N11 != 0) { + for (I = 1; I <= N11; I++) { + X = sqrtf (expf (logf (X) / T1)); + } + } + dummy1 (X); + } + } + // } +} + +void PA (float E[5]) +{ + int J1; + J1 = 0; + L10: + E[1] = (E[1] + E[2] + E[3] - E[4]) * T; + E[2] = (E[1] + E[2] - E[3] + E[4]) * T; + E[3] = (E[1] - E[2] + E[3] + E[4]) * T; + E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2; + J1 = J1 + 1; + if ((J1 - 6) < 0) + goto L10; + return; +} + +void P0 () +{ + E1[J] = E1[K]; + E1[K] = E1[L]; + E1[L] = E1[J]; + return; +} + +void P3 (float *X, float *Y, float *Z) +{ + float Y1; + X1 = *X; + Y1 = *Y; + X1 = T * (X1 + Y1); + Y1 = T * (X1 + Y1); + *Z = (X1 + Y1) / T2; + return; +} \ No newline at end of file diff --git a/testcases/if_sentences.c b/testcases/if_sentences.c new file mode 100644 index 0000000..550b7d3 --- /dev/null +++ b/testcases/if_sentences.c @@ -0,0 +1,54 @@ + +int main() +{ + int a, b, c; + b = 10; + c = 15; + + + // F + if (c == 10) + { + a = 5; + } + + // F + if (c == 10) + { + a = 10; + } + else + { + a = 15; + } + + // F T + if (c == 10 || b == 10) + { + a = 10; + } + + // T T (not taken) + if (c == 15 || b == 10) + { + a = 10; + } + + // T T + if (c == 15 && b == 10) + { + a = 10; + } + + // T F + if (c == 15 && b == 15) + { + a = 10; + } + + // F T + if (c == 10 && b == 15) + { + a = 10; + } +} diff --git a/testcases/matrix.c b/testcases/matrix.c index d46c831..1b52d20 100644 --- a/testcases/matrix.c +++ b/testcases/matrix.c @@ -17,12 +17,12 @@ int main(void) { int m, n, p; volatile UInt16 m3[3][5]; -for(m = 0; m < 3; m++) // 1 +for(m = 0; m < 3; m++) // 1 + 3 * 2 // 3 * 3 { -for(p = 0; p < 5; p++) // 3 +for(p = 0; p < 5; p++) // 3 + 15 * 2 // 15 * 3 { m3[m][p] = 0; // 15: BasicOperation(operation_name='=', type_lhs='unsigned short', type_rhs='unsigned short', type_result='unsigned short') -for(n = 0; n < 4; n++) // 15 +for(n = 0; n < 4; n++) // 15 + 60 * 2 // 60 * 3 { m3[m][p] += m1[m][n] * m2[n][p]; }