test/gensuitemaker.py
author us@chu.huenfield.org
Tue, 25 Dec 2018 14:46:45 +0100
branchsync
changeset 3209 c15b4ca2b52a
parent 2941 23726372aea0
child 3249 03119f76ea35
permissions -rw-r--r--
Replace use of Sequoia's backend with a custom key store.

- Sequoia's key store doesn't meet pep's needs (in particular, the
ability to search on a key's user id) and trying to shoehorn pep's
needs onto Sequoia's key store abstractions is just introducing
overhead with no appreciable gain in functionality.

- This patch changes the Sequoia backend to use a local sqlite
database to store the public keys.
krista@2645
     1
# This file is under GNU General Public License 3.0
krista@2645
     2
# see LICENSE.txt
krista@2941
     3
import argparse
krista@2645
     4
from os import listdir, getcwd
krista@2645
     5
from os.path import isfile, join
krista@2645
     6
from re import sub
krista@2645
     7
import datetime
krista@2645
     8
krista@2645
     9
srcpath = join(getcwd(), "src/engine_tests")
krista@2645
    10
krista@2645
    11
ls = listdir(srcpath)
krista@2645
    12
krista@2645
    13
suites = []
krista@2645
    14
krista@2645
    15
indent = "    "
krista@2645
    16
krista@2941
    17
parser = argparse.ArgumentParser()
krista@2941
    18
parser.add_argument("--exclude", "-x", help="Comma-separated list of tests to exclude from test suite build")
krista@2941
    19
krista@2941
    20
args = parser.parse_args()
krista@2941
    21
krista@2941
    22
exclude_arg = args.exclude
krista@2941
    23
exclude_list = []
krista@2941
    24
if exclude_arg:
krista@2941
    25
    exclude_list = exclude_arg.split(",")
krista@2941
    26
    for x in exclude_list:
krista@2941
    27
        x.replace(" ","")
krista@2645
    28
for f in ls:
krista@2645
    29
    if isfile(join(srcpath, f)):
krista@2645
    30
        if (f.endswith(".cc")):
krista@2645
    31
            suite = sub('\.cc$', '', f)
krista@2941
    32
            if not suite in exclude_list:
krista@2941
    33
                suites.append(suite)
krista@2645
    34
krista@2645
    35
license = (''
krista@2645
    36
'// This file is under GNU General Public License 3.0\n'
krista@2645
    37
'// see LICENSE.txt\n\n')
krista@2645
    38
krista@2645
    39
krista@2645
    40
header = license + "//\n// src/SuiteMaker.cc generated by gensuitemaker.py - changes may be overwritten. You've been warned!\n//\n\n"
krista@2645
    41
krista@2645
    42
header += (''
krista@2645
    43
'#include <cpptest.h>\n'
krista@2645
    44
'#include <cpptest-suite.h>\n'
krista@2645
    45
'#include <memory>\n'
krista@2645
    46
'#include <vector>\n'
krista@2645
    47
'#include "SuiteMaker.h"\n')
krista@2645
    48
krista@2645
    49
suiteincludes = ""
krista@2645
    50
krista@2645
    51
for s in suites:
krista@2645
    52
    suiteincludes += '#include "' + s + '.h"\n'
krista@2645
    53
krista@2645
    54
output = header + "\n// Begin where we generate stuff\n" + suiteincludes + "\n"
krista@2645
    55
krista@2645
    56
output += ("\n"
krista@2645
    57
"const char* SuiteMaker::all_suites[] = {\n")
krista@2645
    58
krista@2645
    59
first = True
krista@2645
    60
krista@2645
    61
for s in suites:
krista@2645
    62
    output += indent + '"' + s + '",\n'
krista@2645
    63
krista@2645
    64
output += "};\n\n"
krista@2645
    65
krista@2645
    66
output += (
krista@2645
    67
'// This file is generated, so magic constants are ok.\n'
krista@2645
    68
'int SuiteMaker::num_suites = ')
krista@2645
    69
krista@2645
    70
output += str(len(suites)) + ";\n\n"
krista@2645
    71
    
krista@2645
    72
output += "void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {\n"
krista@2645
    73
krista@2645
    74
first = True
krista@2645
    75
krista@2645
    76
for s in suites:
krista@2645
    77
    output += indent
krista@2645
    78
    
krista@2645
    79
    if not first:
krista@2645
    80
        output += "else "
krista@2645
    81
    else:
krista@2645
    82
        first = False
krista@2645
    83
    
krista@2645
    84
    output += ('if (strcmp(test_class_name, "' + s + '") == 0)\n' + 
krista@2645
    85
               indent + indent + '*test_suite = new ' + s + '(test_class_name, test_home);\n')
krista@2645
    86
        
krista@2645
    87
output += "}\n\n"
krista@2645
    88
krista@2645
    89
output += (
krista@2645
    90
'void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
krista@2645
    91
'    for (int i = 0; i < num_to_run; i++) {\n'
krista@2645
    92
'        Test::Suite* suite = NULL;\n'
krista@2645
    93
'        SuiteMaker::suitemaker_build(test_class_names[i], test_home, &suite);\n'
krista@2645
    94
'        if (!suite)\n'
krista@2645
    95
'            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously\n'
krista@2645
    96
'        test_suites.push_back(suite);\n'
krista@2645
    97
'    }\n'    
krista@2645
    98
'}'
krista@2645
    99
'\n'
krista@2645
   100
'void SuiteMaker::suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
krista@2645
   101
'    SuiteMaker::suitemaker_buildlist(SuiteMaker::all_suites, SuiteMaker::num_suites, test_home, test_suites);\n'
krista@2645
   102
'}\n\n')
krista@2645
   103
krista@2645
   104
suitemaker = open("src/SuiteMaker.cc", 'w') 
krista@2645
   105
suitemaker.write(output)
krista@2645
   106
suitemaker.close()
krista@2645
   107
krista@2645
   108
generated_at = ("src/SuiteMaker.cc" + " generated at " + datetime.datetime.now().strftime('%c'))
krista@2645
   109
print(generated_at)