Commit fb91ad6b authored by Anas Nashif's avatar Anas Nashif Committed by Anas Nashif
Browse files

sanitycheck: adapt for cmake

parent 969f3930
Loading
Loading
Loading
Loading
+49 −22
Original line number Diff line number Diff line
@@ -672,7 +672,17 @@ class MakeGenerator:
"""

    MAKE_RULE_TMPL = """\t@echo sanity_test_{phase} {goal} >&2
\t$(MAKE) -C {directory} O={outdir} V={verb} EXTRA_CFLAGS="-Werror {cflags}" EXTRA_ASMFLAGS=-Wa,--fatal-warnings EXTRA_LDFLAGS=--fatal-warnings {args} >{logfile} 2>&1
\tcmake  \\
\t\t-H{directory}\\
\t\t-B{outdir}\\
\t\t-DEXTRA_CFLAGS="-Werror {cflags}"\\
\t\t-DEXTRA_AFLAGS=-Wa,--fatal-warnings\\
\t\t-DEXTRA_LDFLAGS=--fatal-warnings\\
\t\t{args}\\
\t\t>{logfile} 2>&1
\t$(MAKE) -C {outdir}\\
\t\tVERBOSE={verb} {make_args}\\
\t\t>>{logfile} 2>&1
"""

    GOAL_FOOTER_TMPL = "\t@echo sanity_test_finished {goal} >&2\n\n"
@@ -700,9 +710,15 @@ class MakeGenerator:
    def _get_rule_header(self, name):
        return MakeGenerator.GOAL_HEADER_TMPL.format(goal=name)

    def _get_sub_make(self, name, phase, workdir, outdir, logfile, args):
    def _get_sub_make(self, name, phase, workdir, outdir, logfile, args, make_args=""):
        """
        @param      args Arguments given to CMake
        @param make_args Arguments given to the Makefile generated by CMake
        """
        verb = "1" if VERBOSE else "0"
        args = " ".join(args)
        args      = " ".join(["-D{}".format(a) for a in args])
        #print(make_args)
        #make_args = " ".join(make_args)

        if self.asserts:
            cflags="-DCONFIG_ASSERT=1 -D__ASSERT_ON=2"
@@ -713,12 +729,25 @@ class MakeGenerator:
            cflags = cflags + "  -Wno-deprecated-declarations"

        if self.ccache:
            args = args + " USE_CCACHE=1"

        return MakeGenerator.MAKE_RULE_TMPL.format(phase=phase, goal=name,
                                                   outdir=outdir, cflags=cflags,
                                                   directory=workdir, verb=verb,
                                                   args=args, logfile=logfile)
            # CMake enables ccache by default when installed
            #
            # sanitycheck requires the user to explicitly enable
            # ccache
            pass
        else:
            args += " -DUSE_CCACHE=0"

        return MakeGenerator.MAKE_RULE_TMPL.format(
            phase=phase,
            goal=name,
            outdir=outdir,
            cflags=cflags,
            directory=workdir,
            verb=verb,
            args=args,
            logfile=logfile,
            make_args=make_args
        )

    def _get_rule_footer(self, name):
        return MakeGenerator.GOAL_FOOTER_TMPL.format(goal=name)
@@ -727,7 +756,7 @@ class MakeGenerator:
        if not os.path.exists(outdir):
            os.makedirs(outdir)

    def add_build_goal(self, name, directory, outdir, args, buildlog):
    def add_build_goal(self, name, directory, outdir, args, buildlog, make_args=""):
        """Add a goal to invoke a Kbuild session

        @param name A unique string name for this build goal. The results
@@ -743,7 +772,7 @@ class MakeGenerator:
        build_logfile = os.path.join(outdir, buildlog)
        text = (self._get_rule_header(name) +
                self._get_sub_make(name, "building", directory,
                                   outdir, build_logfile, args) +
                                   outdir, build_logfile, args, make_args=make_args) +
                self._get_rule_footer(name))
        self.goals[name] = MakeGoal(name, text, None, self.logfile, build_logfile,
                                    None, None)
@@ -781,7 +810,7 @@ class MakeGenerator:
                                   outdir, build_logfile, args) +
                self._get_sub_make(name, "running", directory,
                                   outdir, run_logfile,
                                   args + ["run"]) +
                                   args, make_args="run") +
                self._get_rule_footer(name))
        self.goals[name] = MakeGoal(name, text, q, self.logfile, build_logfile,
                                    run_logfile, qemu_logfile)
@@ -813,13 +842,11 @@ class MakeGenerator:
            by execute() will be keyed by its .name field.
        """
        args = ti.test.extra_args[:]
        arg_list = [
                "ARCH=%s" % ti.platform.arch,
                "BOARD=%s" % ti.platform.name]
        if len(ti.test.extra_configs) > 0:
            arg_list.append("OVERLAY_CONFIG=%s" % os.path.join(ti.outdir, "overlay.conf"))
            args.append("OVERLAY_CONFIG=%s" % os.path.join(ti.outdir, "overlay.conf"))

        args.extend(arg_list)
        args.append("ARCH={}" .format(ti.platform.arch))
        args.append("BOARD={}".format(ti.platform.name))
        args.extend(extra_args)
        if (ti.platform.qemu_support and (not ti.build_only) and
            (not build_only) and (enable_slow or not ti.test.slow)):
@@ -1229,7 +1256,7 @@ class TestInstance:

        @return A SizeCalculator object
        """
        fns = glob.glob(os.path.join(self.outdir, "*.elf"))
        fns = glob.glob(os.path.join(self.outdir, "zephyr", "*.elf"))
        fns = [x for x in fns if not x.endswith('_prebuilt.elf')]
        if (len(fns) != 1):
            raise BuildError("Missing/multiple output ELF binary")
@@ -1475,8 +1502,8 @@ class TestSuite:
                    if (tc.tc_filter and (plat.default or all_plats or platform_filter) and
                        toolchain in plat.supported_toolchains):
                        args = tc.extra_args[:]
                        args.extend(["ARCH=" + plat.arch,
                                "BOARD=" + plat.name, "config-sanitycheck"])
                        args.append("ARCH={}" .format(plat.arch))
                        args.append("BOARD={}".format(plat.name))
                        args.extend(extra_args)
                        # FIXME would be nice to use a common outdir for this so that
                        # conf, gen_idt, etc aren't rebuilt for every  combination,
@@ -1484,10 +1511,10 @@ class TestSuite:
                        # each other since they all try to build them simultaneously

                        o = os.path.join(self.outdir, plat.name, tc.path)
                        dlist[tc, plat, tc.name.split("/")[-1]] = os.path.join(o,".config-sanitycheck")
                        dlist[tc, plat, tc.name.split("/")[-1]] = os.path.join(o,"zephyr", ".config")
                        goal = "_".join([plat.name, "_".join(tc.name.split("/")), "config-sanitycheck"])
                        mg.add_build_goal(goal, os.path.join(ZEPHYR_BASE, tc.code_location), o,
                                args, "config-sanitycheck.log")
                                args, "config-sanitycheck.log", make_args="config-sanitycheck")

        info("Building testcase defconfigs...")
        results = mg.execute(defconfig_cb)