Exemple #1
0
 def test_output_make_solution_cpp(self):
     mf = Makefile('Makefile', 'solution', True)
     mf.run_makefile()
     correct = [
         'g++ solution.cpp -g -Wall -std=gnu++11 -o solution',
         'touch test.xyz'
     ]
     self.assertEqual(mf.output, correct)
Exemple #2
0
 def test_output_make_all(self):
     mf = Makefile('Makefile', '', True)
     mf.run_makefile()
     correct = [
         'gcc -std=gnu99 -Wall -c -o hello.o hello.c',
         'gcc -std=gnu99 -Wall -c -o main.o main.c',
         'gcc -o hello main.o hello.o'
     ]
     self.assertEqual(mf.output, correct)
Exemple #3
0
 def test_output_make_make(self):
     # mf needs to set just_print to false in order to test mf2
     mf = Makefile('Makefile', '', False)
     mf.run_makefile()
     mf2 = Makefile('Makefile', '', True)
     mf2.run_makefile()
     correct = []
     self.assertEqual(mf2.output, correct)
Exemple #4
0
 def setUp(self):
     self.module = "vector"
     self.writerfake = WriterFake()
     self.makefile = Makefile(self.writerfake)
     self.cmd_tadd = CommandAdd(self.makefile,
                                self.writerfake,
                                template=True)
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    # generate makefile
    mkf = Makefile()
    mkf.add_fc_test_source("test.c")
    mkf.add_cl_test_source("cluster.c")
    mkf.add_cl_prog_source("func/dotp.c")
    mkf.write()

    for length in [22, 23, 1024, 1025]:
        for a_stride, b_stride in [(1, 1), (4, 1), (8, 4)]:
            # generate the stimuli
            vec_a, vec_b, exp_result = gen_stimuli(length, a_stride, b_stride)

            # prepare header file
            header = HeaderFile("test_stimuli.h")
            header.add(HeaderConstant("LENGTH", length))
            header.add(HeaderConstant("EXP_RESULT", exp_result))
            header.add(HeaderConstant("A_STRIDE", a_stride))
            header.add(HeaderConstant("B_STRIDE", b_stride))
            header.add(HeaderArray("vec_a", "int8_t", vec_a.ravel()))
            header.add(HeaderArray("vec_b", "int8_t", vec_b.ravel()))
            header.write()

            # compile and run
            os.system("make clean all run > {}".format(RESULT_FILE))

            # parse output
            result = parse_output(RESULT_FILE)

            # log the result
            subcase_name = "length: {}, stride: {}x{}".format(
                length, a_stride, b_stride)
            logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    # generate makefile
    mkf = Makefile()
    mkf.add_fc_test_source("test.c")
    mkf.add_cl_test_source("cluster.c")
    mkf.add_cl_prog_source("func/flip.c")
    mkf.write()

    for outer_len in [16, 17, 18, 19]:
        for inner_len in [256, 257, 258, 259]:
            # generate the stimuli
            stim, exp = gen_stimuli(outer_len, inner_len)

            # prepare header file
            header = HeaderFile("test_stimuli.h")
            header.add(HeaderConstant("OUTER_LEN", outer_len))
            header.add(HeaderConstant("OUTER_LEN_ALIGN", align_array_size(outer_len)))
            header.add(HeaderConstant("INNER_LEN", inner_len))
            header.add(HeaderConstant("INNER_LEN_ALIGN", align_array_size(inner_len)))
            header.add(HeaderArray("vec_x", "int8_t", stim))
            header.add(HeaderArray("vec_exp", "int8_t", exp))
            header.write()

            # compile and run
            os.system("make clean all run > {}".format(RESULT_FILE))

            # parse output
            result = parse_output(RESULT_FILE)

            # log the result
            subcase_name = "{}x{}".format(outer_len, inner_len)
            logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
Exemple #7
0
    def build(self):
        envD = dict()
        parEntriesList = ['spmv', 'tpmv']
        c_type = self.typeDict[self.op.dataType]
        self.hls.params.setDtype(c_type)
        envD["BLAS_dataType"] = c_type
        self.typeStr = 'd%s' % c_type
        if self.opClass == 'BLAS_L1':
            r_type = self.typeDict[self.op.rtype]
            self.typeStr = 'd%s_r%s' % (c_type, r_type)
            envD["BLAS_resDataType"] = r_type
            self.hls.params.setRtype(r_type)

        if self.op.name in parEntriesList:
            envD["BLAS_parEntries"] = "%d" % self.parEntries

        with self.makelock:
            make = Makefile(self.makefile, self.libPath)
            libPath = make.make(envD, self.testPath)
        self.lib = C.cdll.LoadLibrary(libPath)
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    # generate makefile
    mkf = Makefile()
    mkf.add_fc_test_source("test.c")
    mkf.add_cl_test_source("cluster.c")
    mkf.add_cl_prog_source("func/transform.c")
    mkf.write()

    for size in [1024, 1025, 1026, 1027]:
        # generate the stimuli
        x, y, y_bias = gen_stimuli(size, scale_factor=SCALE_FACTOR, bias=BIAS, max_val=2560)

        # prepare header file
        header = HeaderFile("test_stimuli.h")
        header.add(HeaderConstant("LENGTH", size))
        header.add(HeaderScalar("div_factor", "int32_t", SCALE_FACTOR))
        header.add(HeaderScalar("bias", "int32_t", BIAS))
        header.add(HeaderArray("vec_x", "int32_t", x))
        header.add(HeaderArray("vec_exp", "int8_t", y))
        header.add(HeaderArray("vec_exp_bias", "int8_t", y_bias))
        header.write()

        # compile and run
        os.system("make clean all run > {}".format(RESULT_FILE))

        # parse output
        result = parse_output(RESULT_FILE)

        # log the result
        subcase_name = "n={}".format(size)
        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
Exemple #9
0
def main():
    args = read_arguments()
    if args.file:
        # if -f flag was used to specify the makefile
        file_name = args.file
        # quit if this is not a valid file path
        if not os.path.exists(file_name) or not os.path.isfile(file_name):
            error('The file {} could not be found.'.format(file_name))
    else:
        file_name = ''
        # search the current directory for a makefile
        for path in os.listdir(os.getcwd()):
            if os.path.isfile(path):
                if os.path.basename(path).lower() == 'makefile':
                    file_name = path
                    break
        # quit if no makefile was found
        if not file_name:
            error('Makefile not found.')

    mkfile = Makefile(file_name, args.target, args.just_print)
    mkfile.run_makefile()
Exemple #10
0
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    for intrinsic, simd, flip_layers, parallel, stream, xcorr, fuse, no_div, reorder, dup_inp in [
            (False, False, False, False, False, False, False, False, False, False),
            (True, False, False, False, False, False, False, False, False, False),
            (True, True, False, False, False, False, False, False, False, False),
            (True, True, True, False, False, False, False, False, False, False),
            (True, True, True, True, False, False, False, False, False, False),
            (True, True, True, True, True, False, False, False, False, False),
            (True, True, True, True, True, True, False, False, False, False),
            (True, True, True, True, True, True, True, False, False, False),
            (True, True, True, True, True, True, True, True, False, False),
            (True, True, True, True, True, True, True, True, True, False),
            (True, True, True, True, True, True, True, True, True, True)
    ]:

        # generate makefile
        mkf = Makefile()
        mkf.add_fc_test_source("test.c")
        mkf.add_cl_test_source("cluster.c")
        mkf.add_cl_prog_source("net/model.c")
        mkf.add_cl_prog_source("net/layer1.c")
        mkf.add_cl_prog_source("net/layer2.c")
        mkf.add_cl_prog_source("net/layer3.c")
        mkf.add_cl_prog_source("net/layer4.c")
        mkf.add_cl_prog_source("net/layer5.c")
        mkf.add_cl_prog_source("net/fused_layer_1_2.c")
        mkf.add_cl_prog_source("net/net.c")
        mkf.add_cl_prog_source("func/transform.c")
        mkf.add_cl_prog_source("func/dotp.c")
        mkf.add_cl_prog_source("func/conv.c")
        mkf.add_cl_prog_source("func/flip.c")
        mkf.add_cl_prog_source("func/xcorr.c")

        if not simd:
            mkf.add_define("NO_SIMD")
        if flip_layers:
            mkf.add_define("FLIP_LAYERS")
        if parallel:
            mkf.add_define("PARALLEL")
        if intrinsic:
            mkf.add_define("INTRINSIC_SCALE")
        if stream:
            mkf.add_define("DMA_STREAM")
        if xcorr:
            mkf.add_define("CROSS_CORRELATE")
        if fuse:
            mkf.add_define("FUSE_LAYERS")
        if no_div:
            mkf.add_define("NO_INTERMEDIATE_SCALE")
        if dup_inp:
            mkf.add_define("DUPLICATE_FEATUREMAP")
        if reorder:
            mkf.add_define("REORDER_BN")

        mkf.write()

        # generate the stimuli
        _, x_align, _, y_exp_align = gen_stimuli(no_div=no_div, pad_data=dup_inp, reorder_bn=reorder)

        # prepare header file
        header = HeaderFile("test_stimuli.h")
        header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
        header.add(HeaderArray("y_exp_vec", "int8_t", y_exp_align.ravel()))
        header.write()

        # compile and run
        os.system("make clean all run > {}".format(RESULT_FILE))

        # parse output
        result = parse_output(RESULT_FILE)

        # skip the naive result
        if not flip_layers:
            result["1"]["result"] = None

        # prepare the case name
        subcase_name = "naive"
        if intrinsic:
            subcase_name = "+ intrinsic scale"
        if simd:
            subcase_name = "+ SIMD"
        if flip_layers:
            subcase_name = "+ flip"
        if parallel:
            subcase_name = "+ parallel"
        if stream:
            subcase_name = "+ double buffering"
        if xcorr:
            subcase_name = "+ cross correlations"
        if fuse:
            subcase_name = "+ fused layer 1+2"
        if no_div:
            subcase_name = "+ no division after layer 1"
        if reorder:
            subcase_name = "+ reorder BN"
        if dup_inp:
            subcase_name = "+ duplicate featuremap"

        # log the result
        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
Exemple #11
0
 def test_output_make_clean(self):
     mf = Makefile('Makefile', 'clean', True)
     mf.run_makefile()
     correct = ['rm solution test.xyz']
     self.assertEqual(mf.output, correct)
Exemple #12
0
 def test_output_make_clean_make(self):
     mf = Makefile('Makefile', '', False)
     mf.run_makefile()
     mf2 = Makefile('Makefile', 'clean', False)
     mf2.run_makefile()
     mf3 = Makefile('Makefile', '', True)
     mf3.run_makefile()
     correct = [
         'gcc -std=gnu99 -Wall -c -o hello.o hello.c',
         'gcc -std=gnu99 -Wall -c -o main.o main.c',
         'gcc -o hello main.o hello.o'
     ]
     self.assertEqual(mf3.output, correct)
Exemple #13
0
 def setUp(self):
     self.project_name = "matrix"
     self.writerfake = WriterFake()
     self.makefile = Makefile(self.writerfake)
     self.cmd_init = CommandInit(self.makefile, self.writerfake)
Exemple #14
0
 def test_output_make_clean(self):
     mf = Makefile('Makefile', 'clean', True)
     mf.run_makefile()
     correct = ['rm -f hello *.o']
     self.assertEqual(mf.output, correct)
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    for intrinsic_conv_scale in [False, True]:
        for simd in [False, True]:
            for parallel in [False, True]:
                for cross_correlate in [False, True]:

                    if not simd and (parallel or cross_correlate):
                        continue

                    # parallel requires intrinsic conv scale
                    if parallel and not intrinsic_conv_scale:
                        continue

                    # not implemented
                    if cross_correlate and not parallel:
                        continue

                    # generate makefile
                    mkf = Makefile()
                    mkf.add_fc_test_source("test.c")
                    mkf.add_cl_test_source("cluster.c")
                    mkf.add_cl_prog_source("net/layer1.c")
                    mkf.add_cl_prog_source("net/net.c")
                    mkf.add_cl_prog_source("func/conv.c")
                    mkf.add_cl_prog_source("func/xcorr.c")
                    mkf.add_cl_prog_source("func/transform.c")

                    if parallel:
                        mkf.add_define("PARALLEL")
                    if intrinsic_conv_scale:
                        mkf.add_define("INTRINSIC_SCALE")
                    if cross_correlate:
                        mkf.add_define("CROSS_CORRELATE")
                    if not simd:
                        mkf.add_define("NO_SIMD")

                    mkf.write()

                    random_input = False

                    # generate the stimuli
                    x, y_exp = gen_stimuli(random_input)
                    x_align = align_array(x)
                    y_exp_align = align_array(y_exp)

                    # prepare header file
                    header = HeaderFile("test_stimuli.h")
                    header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
                    header.add(
                        HeaderArray("y_exp_vec", "int8_t",
                                    y_exp_align.ravel()))
                    header.write()

                    # compile and run
                    os.system("make clean all run > {}".format(RESULT_FILE))

                    # parse output
                    result = parse_output(RESULT_FILE)

                    # log the result
                    options = []
                    if simd:
                        options.append("simd")
                    if parallel:
                        options.append("par")
                    if intrinsic_conv_scale:
                        options.append("intr.s.")
                    if cross_correlate:
                        options.append("xcorr")

                    subcase_name = "Layer 1 "
                    if options:
                        subcase_name += "; ".join(options)
                    else:
                        subcase_name += "naive"

                    logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    for size_a, size_b in [(155, 16), (1188, 64), (4096, 128)]:
        for conv_version in [0, 1, 2, 3]:

            div_factor = 128 * size_b // 8
            offset = 10 * div_factor

            # generate makefile
            mkf = Makefile()
            mkf.add_fc_test_source("test.c")
            mkf.add_cl_test_source("cluster.c")
            mkf.add_cl_prog_source("func/conv.c")
            mkf.add_define("CONV_VERSION", conv_version)
            mkf.write()

            # generate the stimuli
            vecA, vecB, vecExp = gen_stimuli(size_a, size_b, div_factor,
                                             offset)

            # prepare header file
            header = HeaderFile("test_stimuli.h")
            header.add(HeaderConstant("LENGTH_A", size_a))
            header.add(HeaderConstant("LENGTH_B", size_b))
            header.add(HeaderConstant("LENGTH_RES", len(vecExp)))
            header.add(HeaderConstant("FACTOR", div_factor))
            header.add(HeaderConstant("OFFSET", offset))
            header.add(HeaderArray("vecA", "int8_t", vecA))
            header.add(HeaderArray("vecB", "int8_t", vecB))
            header.add(HeaderArray("vecExp", "int8_t", vecExp))
            header.write()

            # compile and run
            os.system("make clean all run > {}".format(RESULT_FILE))

            # parse output
            result = parse_output(RESULT_FILE)

            casename = "V{}, {}x{}".format(conv_version, size_a, size_b)

            # log the result
            logger.show_subcase_result(casename, result)

    # return summary
    return logger.summary()
Exemple #17
0
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME)

    for no_intermediate_scale, duplicate_featuremap in [(False, False),
                                                        (True, False),
                                                        (True, True)]:

        # generate makefile
        # mkf = Makefile(opt_level=2 if duplicate_featuremap else 3)
        mkf = Makefile(opt_level=3)
        mkf.add_fc_test_source("test.c")
        mkf.add_cl_test_source("cluster.c")
        mkf.add_cl_prog_source("net/fused_layer_1_2.c")
        mkf.add_cl_prog_source("net/net.c")
        mkf.add_cl_prog_source("func/conv.c")
        mkf.add_cl_prog_source("func/xcorr.c")
        mkf.add_cl_prog_source("func/dotp.c")
        mkf.add_cl_prog_source("func/transform.c")

        mkf.add_define("PARALLEL")
        mkf.add_define("INTRINSIC_SCALE")
        mkf.add_define("CROSS_CORRELATE")
        mkf.add_define("FUSE_LAYERS")
        mkf.add_define("DEFAULT_DIM")

        if no_intermediate_scale:
            mkf.add_define("NO_INTERMEDIATE_SCALE")

        if duplicate_featuremap:
            mkf.add_define("DUPLICATE_FEATUREMAP")

        mkf.write()

        random_input = False

        # generate the stimuli
        _, x_align, _, y_exp_align = gen_stimuli(random_input,
                                                 no_intermediate_scale,
                                                 duplicate_featuremap)

        # prepare header file
        header = HeaderFile("test_stimuli.h")
        header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
        header.add(HeaderArray("y_exp_vec", "int8_t", y_exp_align.ravel()))
        header.write()

        # compile and run
        os.system("make clean all run > {}".format(RESULT_FILE))

        # parse output
        result = parse_output(RESULT_FILE)

        # log the result
        options = []
        if no_intermediate_scale:
            options.append("no scale")
        if duplicate_featuremap:
            options.append("dup inp")

        subcase_name = "Fused Layer 1+2 "
        if options:
            subcase_name += "; ".join(options)

        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME, show_title=False)

    for simd in [False, True]:

        # generate makefile
        mkf = Makefile()
        mkf.add_fc_test_source("test.c")
        mkf.add_cl_test_source("cluster.c")
        mkf.add_cl_prog_source("net/layer5.c")
        mkf.add_cl_prog_source("net/net.c")
        mkf.add_cl_prog_source("func/transform.c")
        mkf.add_cl_prog_source("func/dotp.c")
        mkf.write()

        if not simd:
            mkf.add_define("NO_SIMD")

        random_input = False

        # generate the stimuli
        _, x_align, _, y_exp_align = gen_stimuli(random_input)

        # prepare header file
        header = HeaderFile("test_stimuli.h")
        header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
        header.add(HeaderArray("y_exp_vec", "int8_t", y_exp_align.ravel()))
        header.write()

        # compile and run
        os.system("make clean all run > {}".format(RESULT_FILE))

        # parse output
        result = parse_output(RESULT_FILE)

        # log the result
        subcase_name = "Layer 5 "
        if simd:
            subcase_name += "simd"
        else:
            subcase_name += "naive"
        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME, show_title=False)

    for simd in [False, True]:
        for flip_layers in [False, True]:
            for parallel in [False, True]:
                for dma_stream in [False, True]:
                    for reorder in [False, True]:

                        if not simd and (flip_layers or parallel or dma_stream or reorder):
                            continue

                        if not flip_layers and (parallel or dma_stream):
                            # not implemented
                            continue

                        if not parallel and dma_stream:
                            # not implemented
                            continue

                        # generate makefile
                        mkf = Makefile()
                        mkf.add_fc_test_source("test.c")
                        mkf.add_cl_test_source("cluster.c")
                        mkf.add_cl_prog_source("net/layer2.c")
                        mkf.add_cl_prog_source("net/net.c")
                        mkf.add_cl_prog_source("func/transform.c")
                        mkf.add_cl_prog_source("func/dotp.c")

                        if not simd:
                            mkf.add_define("NO_SIMD")

                        if flip_layers:
                            mkf.add_define("FLIP_LAYERS")

                        if parallel:
                            mkf.add_define("PARALLEL")

                        if dma_stream:
                            mkf.add_define("DMA_STREAM")

                        if reorder:
                            mkf.add_define("REORDER_BN")

                        mkf.write()

                        random_input = False

                        # generate the stimuli
                        _, x_align, _, y_exp_align = gen_stimuli(random_input, flip_layers, reorder)

                        # prepare header file
                        header = HeaderFile("test_stimuli.h")
                        header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
                        header.add(HeaderArray("y_exp_vec", "int8_t", y_exp_align.ravel()))
                        header.write()

                        # compile and run
                        os.system("make clean all run > {}".format(RESULT_FILE))

                        # parse output
                        result = parse_output(RESULT_FILE)

                        # log the result
                        subcase_name = "Layer 2 "

                        options = []
                        if simd:
                            options.append("simd")
                        if flip_layers:
                            options.append("flip")
                        if parallel:
                            options.append("par")
                        if dma_stream:
                            options.append("stream")
                        if reorder:
                            options.append("reorder")

                        if options:
                            subcase_name += "; ".join(options)
                        else:
                            subcase_name += "naive"

                        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
Exemple #20
0
 def test_cycle(self):
     mf = Makefile('Makefile', 'cycle', True)
     # sys.exit should be called
     with self.assertRaises(SystemExit):
         mf.run_makefile()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME, show_title=False)

    for simd, parallel in [(False, False), (True, False), (True, True)]:

        # generate makefile
        mkf = Makefile()
        mkf.add_fc_test_source("test.c")
        mkf.add_cl_test_source("cluster.c")
        mkf.add_cl_prog_source("net/layer3.c")
        mkf.add_cl_prog_source("net/net.c")
        mkf.add_cl_prog_source("func/transform.c")
        mkf.add_cl_prog_source("func/conv.c")

        if not simd:
            mkf.add_define("NO_SIMD")

        if parallel:
            mkf.add_define("PARALLEL")

        mkf.write()

        random_input = False

        # generate the stimuli
        _, x_align, _, y_exp_align = gen_stimuli(random_input)

        # prepare header file
        header = HeaderFile("test_stimuli.h")
        header.add(HeaderArray("x_vec", "int8_t", x_align.ravel()))
        header.add(HeaderArray("y_exp_vec", "int8_t", y_exp_align.ravel()))
        header.write()

        # compile and run
        os.system("make clean all run > {}".format(RESULT_FILE))

        # parse output
        result = parse_output(RESULT_FILE)

        # log the result
        options = []
        if simd:
            options.append("simd")
        if parallel:
            options.append("parallel")

        subcase_name = "layer 3 "
        if options:
            subcase_name += " + ".join(options)
        else:
            subcase_name += "naive"
        logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()
Exemple #22
0
from makefile import Makefile
from writer import Writer
from .add import CommandAdd
from .command_interface import CommandInterface
from .command_update import CommandUpdate
from .delete import CommandDelete
from .install import CommandInstall
from .init import CommandInit
from .remove import CommandRemove
from .run import CommandRun
from .build import CommandBuild
from .version import CommandVersion

writer = Writer()
makefile_processor = Makefile(writer)

commands = {
    'add': CommandAdd(makefile_processor, writer),
    'init': CommandInit(makefile_processor, writer),
    'tadd': CommandAdd(makefile_processor, writer, template=True),
    'delete': CommandDelete(makefile_processor, writer),
    'run': CommandRun(makefile_processor, writer),
    'build': CommandBuild(makefile_processor, writer),
    'version': CommandVersion()
}


def initialize_command(command: str) -> CommandInterface:
    """
    This method creates a new command
Exemple #23
0
    def setUp(self):
        self.package = "matrix"
        self.action = "vector"

        self.writerfake = WriterFake()
        self.makefile = Makefile(self.writerfake)
Exemple #24
0
class TestMakefile(TestCase):
    def setUp(self):
        self.package = "matrix"
        self.action = "vector"

        self.writerfake = WriterFake()
        self.makefile = Makefile(self.writerfake)

    def test_generate(self):
        expected_lines = [
            "CC=g++",
            "CFLAGS=-g -std=c++17 -Wall -Wextra -Iinclude -Iutils",
            "\n",
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o {package} src\\main.cc".format(package=self.package),
            "\n"
        ]

        self.makefile.generate(self.package)

        final_lines = self.writerfake.get_lines()
        self.assertEqual(expected_lines, final_lines)

    def test_add_variable(self):
        expected_lines = ["CC=g++"]

        self.makefile.add_variable('Makefile', 'CC', 'g++')

        final_lines = self.writerfake.get_lines()
        self.assertEqual(expected_lines, final_lines)

    def test_add_action(self):
        expected_lines = [
            "all: src\\main.cc build\\{action}.o".format(action=self.action),
            "\t$(CC) $(CFLAGS) -o {package} src\\main.cc build\\{action}.o".format(package=self.package, action=self.action),
            "\n",
            "build\\{action}.o: include\\{action}.h src\\{action}.cc".format(action=self.action),
            "\t$(CC) $(CFLAGS) -c -o build\\{action}.o src\\{action}.cc".format(action=self.action)
        ]

        self.makefile.add_base_all_action('Makefile', self.package)
        self.makefile.add_action(self.action)

        written_lines = self.writerfake.get_lines()
        self.assertEqual(expected_lines, written_lines)

    def test_delete_action(self):
        initial_lines = [
            "all: src\\main.cc build\\{action}.o".format(action=self.action),
            "\t$(CC) $(CFLAGS) -o {package} src\\main.cc build\\{action}.o".format(package=self.package, action=self.action),
            "\n",
            "build\\{action}.o: include\\{action}.h src\\{action}.cc".format(action=self.action),
            "\t$(CC) $(CFLAGS) -c -o build\\{action}.o src\\{action}.cc".format(action=self.action)
        ]
        expected_lines = [
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o {package} src\\main.cc".format(package=self.package),
            "\n"
        ]

        self.writerfake.set_lines(initial_lines)

        self.makefile.delete_action(self.action)

        final_lines = self.writerfake.get_lines()
        self.assertEqual(expected_lines, final_lines)

    def test_update_all_with_util(self):
        new_util = "utils/{action}\\{action}.o".format(action=self.action)

        initial_lines = [
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o {package} src\\main.cc".format(package=self.package),
            "\n"
        ]
        expected_lines = [
            "all: src\\main.cc {util}".format(util=new_util),
            "\t$(CC) $(CFLAGS) -o matrix src\\main.cc {util}".format(util=new_util),
            "\n"
        ]

        self.writerfake.set_lines(initial_lines)
        self.makefile.update_all_with_util('Makefile', self.action)

        self.assertEqual(expected_lines, self.writerfake.get_lines())

    def test_update_all_with_module(self):
        lines = [
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o matrix src\\main.cc",
            "\n"
        ]

        self.writerfake.set_lines(lines)

        lines[0] += " build\\matrix.o"
        lines[1] += " build\\matrix.o"

        self.makefile.update_all_with_module('Makefile', 'matrix')

        self.assertEqual(self.writerfake.get_lines(), lines)

    def test_add_base_all_action_with_separator(self):
        expected_lines = [
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o matrix src\\main.cc",
            "\n"
        ]

        self.makefile.add_base_all_action('Makefile', 'matrix')

        self.assertEqual(self.writerfake.get_lines(), expected_lines)

    def test_add_base_all_action_without_separator(self):
        expected_lines = [
            "all: src\\main.cc",
            "\t$(CC) $(CFLAGS) -o matrix src\\main.cc"
        ]

        self.makefile.add_base_all_action('Makefile', 'matrix', separator=False)

        self.assertEqual(expected_lines, self.writerfake.get_lines())
Exemple #25
0
 def tearDown(self):
     # removes files left after a method e.x. test_output_make_make
     mf = Makefile('Makefile', 'clean', False)
     mf.run_makefile()
def test():
    """
    Execute the tests
    Returns: (n_total, n_success)
    """

    logger = TestLogger(TESTNAME, show_title=False)

    # generate makefile
    mkf = Makefile()
    mkf.add_fc_test_source("test.c")
    mkf.add_cl_test_source("cluster.c")
    mkf.add_cl_prog_source("net/layer3.c")
    mkf.add_cl_prog_source("net/net.c")
    mkf.add_cl_prog_source("func/flip.c")
    mkf.write()

    # generate the stimuli
    _, x_align, _, y_exp_align = gen_stimuli()

    # prepare header file
    header = HeaderFile("test_stimuli.h")
    header.add(HeaderArray("x_vec", "int8_t", x_align.ravel(), const=False))
    header.add(HeaderArray("y_exp", "int8_t", y_exp_align.ravel(),
                           const=False))
    header.write()

    # compile and run
    os.system("make clean all run > {}".format(RESULT_FILE))

    # parse output
    result = parse_output(RESULT_FILE)

    # log the result
    subcase_name = "Layer 3 flip"
    logger.show_subcase_result(subcase_name, result)

    # return summary
    return logger.summary()