blob: d38868b6505faa95ff15a4680ebf1794b933d2aa [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import optparse
import sys
import re
TEMPLATE_PREFIX = '''/*
*
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the \"License\");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* THIS FILE WAS GENERATED AUTOMATICALLY BY THE BUILD SYSTEM.
*/
#include <nlunit-test.h>
'''
# Forward declarations will be added here
TEMPLATE_MAIN_START = '''
int main()
{
int code = 0;
nlTestSetOutputStyle(OUTPUT_CSV);
'''
# Test invokation will be added here
TEMPLATE_SUFFIX = '''
return code;
}'''
def main(argv):
parser = optparse.OptionParser()
parser.add_option('--input_file')
parser.add_option('--output_file')
options, _ = parser.parse_args(argv)
tests = []
TEST_SUITE_RE = re.compile(r'\s*CHIP_REGISTER_TEST_SUITE\(([^)]*)\)')
with open(options.input_file, 'r') as input_file:
for l in input_file.readlines():
match = TEST_SUITE_RE.match(l)
if not match:
continue
tests.append(match.group(1))
if not tests:
print("ERROR: no tests found in '%s'" % input_file)
print("Did you forget to CHIP_REGISTER_TEST_SUITE?")
return 1
with open(options.output_file, 'w') as output_file:
output_file.write(TEMPLATE_PREFIX)
for test in tests:
output_file.write("int %s();\n" % test)
output_file.write("\n")
output_file.write(TEMPLATE_MAIN_START)
for test in tests:
output_file.write(" code = code | (%s());\n" % test)
output_file.write("\n")
output_file.write(TEMPLATE_SUFFIX)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))