Exemple #1
0
def exec_csp_test_case():
    # init logging
    os.environ['SDK_CHECK_TYPE'] = 'csp_check'
    # get rt-thread_sourcr_code : nano and released
    get_rt_thread_source_code()
    # get update csp url
    try:
        with open('/rt-thread/sdk-index/tools/csp_update_url.json', "r") as f:
            sdk_url = json.loads(f.read())[0]
    except Exception as e:
        logging.error("\nError message : {0}.".format(e))
        sys.exit(1)

    execute_command(
        "wget -nv -O /rt-thread/rt-thread-csp.zip {0}".format(sdk_url))
    execute_command(
        "unzip -o /rt-thread/rt-thread-csp.zip -d /rt-thread/rt-thread-csp")
    execute_command("rm -rf /rt-thread/rt-thread-csp.zip")
    rt_thread_csp_dir = os.listdir("/rt-thread/rt-thread-csp")
    if len(rt_thread_csp_dir) != 1:
        logging.error("Please check the zip : {0}".format(sdk_url))
        sys.exit(1)
    csp_path = os.path.join("/rt-thread/rt-thread-csp", rt_thread_csp_dir[0])
    execute_command(
        "mv {0}/* /rt-thread/rt-thread-csp && rm -rf {0}".format(csp_path))

    gen_sdk_para_json_file("/rt-thread/rt-thread-csp", "/rt-thread/workspace",
                           "/rt-thread/rt-thread-src")

    gen_sdk_test_case("csp_chips.json", "mcu_config")
    subprocess.call("python sdk_test_case.py", shell=True)
    execute_command("rm -rf mcu_config")

    sys.exit(0)
Exemple #2
0
def main():
    init_logger()
    execute_command("apt-get update && apt-get -y upgrade && apt-get -y install unzip")
    os.chdir("/rt-thread/sdk-index/tools/csp_check")
    execute_command("python -m pip install --upgrade pip")
    result = execute_command("pip install rt-thread-studio")
    logging.info("{0}".format(result))
    # get update csp url
    try:
        with open('/rt-thread/sdk-index/tools/csp_update_url.json', "r") as f:
            sdk_url = json.loads(f.read())[0]
        # csp ci check
        logging.info("csp check test! : {0}".format(sdk_url))
        os.system("export SDK_CHECK_TYPE=csp_check")
        # os.sytem("python csp_check.py")
        sys.exit(0)
    except Exception as e:
        logging.error("\nError message : {0}.".format(e))

    # get update bsp url
    try:
        with open('/rt-thread/sdk-index/tools/bsp_update_url.json', "r") as f:
            sdk_url = json.loads(f.read())[0]
        # bsp ci chck
        logging.info("bsp check test! : {0}".format(sdk_url))
        os.system("python bsp_check.py")
        sys.exit(0)
    except Exception as e:
        logging.error("\nError message : {0}.".format(e))
        sys.exit(1)
Exemple #3
0
def bsp_check_test():
    init_logger()
    os.environ['SDK_CHECK_TYPE'] = 'bsp_check'
    with open('/rt-thread/sdk-index/tools/bsp_update_url.json', "r") as f:
        bsp_update_url = json.loads(f.read())[0]

    execute_command("wget -O /rt-thread/bsp.zip {0}".format(bsp_update_url))
    execute_command("unzip {0} -d /rt-thread/rt-thread-bsp".format("/rt-thread/bsp.zip"))
    execute_command("rm -rf /rt-thread/bsp.zip")
    prj_path = "/RT-ThreadStudio/plugins/gener/"
    if not os.path.exists(prj_path):
        os.makedirs(prj_path)

    execute_command("cp -r -f {0} {1}".format("prj_gen", "/RT-ThreadStudio/plugins/gener/"))

    # find bsp path
    real_bsp_path = None
    for dir in os.listdir("/rt-thread/rt-thread-bsp"):
        if dir.find("sdk-bsp") != -1:
            real_bsp_path = os.path.join("/rt-thread/rt-thread-bsp", dir)
            logging.info("bsp path : {0}".format(real_bsp_path))
            break
    if real_bsp_path is None:
        logging.error("can't find bsp path, please check it!")

    os.system("ls -al {0}".format(real_bsp_path))
    gen_bsp_sdk_json(real_bsp_path, "/rt-thread/sdk-index/", "/rt-thread/workspace/")
    # gen test case
    gen_chip_test_case("bsp_chips.json", "mcu_config")

    os.system("python csp_test_case.py")

    execute_command("exit")
Exemple #4
0
def get_generate_result(csp_json_path):
    execute_command("chmod 777 /RT-ThreadStudio/plugins/gener/prj_gen")
    # judge sdk update type (csp or bsp)
    try:
        check_type = os.environ['SDK_CHECK_TYPE']
    except Exception as e:
        logging.error(": {0}".format(e))

    logging.debug("project_json_info: {0}".format(check_type))
    os.system("cat {0}".format(csp_json_path))

    if check_type.find("csp_check") != -1:
        cmd = r"/RT-ThreadStudio/plugins/gener/prj_gen --csp_project=true --csp_parameter_file={0} -n xxx 2> generate.log".format(
            csp_json_path)
    else:
        cmd = r"/RT-ThreadStudio/plugins/gener/prj_gen --bsp_project=true --bsp_parameter_file={0} -n xxx 2> generate.log".format(
            csp_json_path)
    execute_command(cmd)

    try:
        with open("generate.log", "r") as f:
            log_info = f.readlines()
    except Exception as e:
        print("Error message : {0}".format(e))
    else:
        for line in log_info:
            if line.find("Error") != -1 or line.find(
                    "error") != -1 or line.find("ERROR") != -1:
                logging.error(line)
            else:
                logging.debug(line)
Exemple #5
0
def exec_test_case():
    print("=================> Project build start.")
    begin_time = time.time()
    pytest.main(
        ["sdk_test_case.py", '--html=report.html', '--self-contained-html'])
    execute_command("rm -rf /rt-thread/eclipse/workspace")
    print("=================> Project build end, time consuming : {0}.".format(
        time.time() - begin_time))
def get_generate_result(csp_json_path):
    # judge sdk update type (csp or bsp)
    try:
        check_type = os.environ['SDK_CHECK_TYPE']
    except Exception as e:
        logging.error(": {0}".format(e))

    logging.debug("project_json_info: {0}".format(check_type))
    logging.debug("json path : {0}".format(csp_json_path))
    result = execute_command("cat {0}".format(csp_json_path))
    logging.debug("cat {0} : {1}".format(csp_json_path, result))

    before = os.getcwd()
    log_path = os.path.join(before, "generate.log")

    # csp test case
    if check_type == 'csp_check':
        cmd = r"./prj_gen --csp_project=true --csp_parameter_file={0} -n xxx 2> {1}".format(
            csp_json_path, log_path)
    elif check_type == 'bsp_check':
        try:
            prj_gen_path = os.environ['PRJ_GEN_PATH']
        except Exception as e:
            logging.error(": {0}".format(e))
        else:
            logging.debug("bsp prj_gen path : {}".format(prj_gen_path))
            os.chdir(Path(prj_gen_path))
            real_prj_gen_path = os.path.join(prj_gen_path, "prj_gen")
            cmd = r"{0} --bsp_project=true --bsp_parameter_file={1} -n xxx 2> {2}".format(
                real_prj_gen_path, csp_json_path, log_path)
    else:
        logging.error("Error env : {0}".format(prj_gen_path))
        sys.exit(1)

    execute_command(cmd)
    os.chdir(before)

    try:
        with open(log_path, "r") as f:
            log_info = f.readlines()
    except Exception as e:
        logging.error("Error message : {0}".format(e))
    else:
        for line in log_info:
            if line.find("Error") != -1 or line.find(
                    "error") != -1 or line.find("ERROR") != -1:
                logging.error(line)
            else:
                logging.debug(line)
Exemple #7
0
def get_build_result(cmd_pre, project_name):

    project_path = os.path.join("/rt-thread/workspace", project_name)
    if not os.path.exists(project_path):
        print("Error : {0} not exit.".format(project_path))
        return False

    cmd = cmd_pre + " -cleanBuild '{0}' >build.log 2>&1".format(project_name)
    execute_command(cmd)
    build_result = judge_build_result()

    project_path = os.path.join("/rt-thread/workspace", project_name)
    execute_command("rm -rf {0}".format(project_path))

    return build_result
Exemple #8
0
def gen_sdk_test_case(json_path, mcu_config_path):
    generate_and_import_project(json_path, mcu_config_path)
    test_case = ''
    for config_json in os.listdir(mcu_config_path):
        project_name = config_json.split(".json")[0]
        test_case_example = """
                def test_{0}():
                    assert csp_test("{0}") is True
                """.format(project_name)
        test_case_format = textwrap.dedent(test_case_example)
        test_case += "\n" + test_case_format
        config_json_path = os.path.join(mcu_config_path, config_json)

        execute_command("rm -rf {0}".format(config_json_path))
    with open("sdk_test_case.py", "a") as f:
        f.write(test_case)
def gen_sdk_test_case(json_path, mcu_config_path):
    generate_and_import_project(json_path, mcu_config_path)
    test_case = ''
    for config_json in os.listdir(mcu_config_path):
        project_name = config_json.split(".json")[0]
        new_project_name = re.sub(r"[\#\*\-\/\(\)\[\]\ ]", "_", project_name)
        test_case_example = """
                def test_{0}():
                    print("Build Project: {0}")
                    assert build_test("{0}") is True
                """.format(new_project_name)
        test_case_format = textwrap.dedent(test_case_example)
        test_case += "\n" + test_case_format
        config_json_path = os.path.join(mcu_config_path, config_json)

        execute_command("rm -rf {0}".format(config_json_path))
    with open("sdk_test_case.py", "a") as f:
        f.write(test_case + '\n')
Exemple #10
0
def judge_build_result():
    try:
        with open("build.log", 'r') as f:
            log_info = f.readlines()
    except Exception as e:
        print("Error message : {0}".format(e))
        return False

    build_result = False
    for line in log_info:
        if (line.find('error') != -1) or (line.find("Error") != -1):
            print(line)
        if (line.find("region `ROM' overflowed") !=
                -1) or (line.find("region `RAM' overflowed") != -1):
            print(line)
        if line.find("Finished building target: rtthread.elf") != -1:
            build_result = True
            break
    execute_command("rm -rf build.log")
    return build_result
Exemple #11
0
def exec_bsp_test_case():
    os.environ['SDK_CHECK_TYPE'] = 'bsp_check'
    with open('/rt-thread/sdk-index/tools/bsp_update_url.json', "r") as f:
        bsp_update_url = json.loads(f.read())[0]

    execute_command(
        "wget -nv -O /rt-thread/bsp.zip {0}".format(bsp_update_url))
    execute_command(
        "unzip {0} -d /rt-thread/rt-thread-bsp".format("/rt-thread/bsp.zip"))
    execute_command("rm -rf /rt-thread/bsp.zip")
    prj_path = "/RT-ThreadStudio/plugins/gener/gener/"

    src_path = os.path.join(os.getcwd(), "templates")
    dst_path = os.path.join(prj_path, "templates")
    do_copy_folder(src_path, dst_path)
    do_copy_file("prj_gen", prj_path)

    # set prj_gen_path
    os.environ['PRJ_GEN_PATH'] = prj_path

    # find bsp path
    real_bsp_path = None
    rt_thread_bsp_dir = os.listdir("/rt-thread/rt-thread-bsp")
    if len(rt_thread_bsp_dir) != 1:
        logging.error("Please check the zip : {0}".format(bsp_update_url))
        sys.exit(1)
    real_bsp_path = os.path.join("/rt-thread/rt-thread-bsp",
                                 rt_thread_bsp_dir[0])
    logging.info("bsp path : {0}".format(real_bsp_path))

    board_path = "/RT-ThreadStudio/repo/Extract/Board_Support_Packages/RealThread/board/0.1.1/"
    do_copy_folder(real_bsp_path, board_path)
    gen_bsp_sdk_json(board_path, "/rt-thread/sdk-index/",
                     "/rt-thread/workspace/")
    # gen test case
    gen_sdk_test_case("bsp_chips.json", "mcu_config")
    subprocess.call("python sdk_test_case.py", shell=True)
    execute_command("rm -rf mcu_config")

    sys.exit(0)
Exemple #12
0
def bsp_check_test():
    init_logger()
    os.environ['SDK_CHECK_TYPE'] = 'bsp_check'
    with open('/rt-thread/sdk-index/tools/bsp_update_url.json', "r") as f:
        bsp_update_url = json.loads(f.read())[0]

    execute_command("wget -O /rt-thread/bsp.zip {0}".format(bsp_update_url))
    execute_command(
        "unzip {0} -d /rt-thread/rt-thread-bsp".format("/rt-thread/bsp.zip"))
    execute_command("rm -rf /rt-thread/bsp.zip")
    prj_path = "/RT-ThreadStudio/plugins/gener/gener/"

    src_path = os.path.join(os.getcwd(), "templates")
    dst_path = os.path.join(prj_path, "templates")
    do_copy_folder(src_path, dst_path)
    do_copy_file("prj_gen", prj_path)

    logging.info("ls -al {0}".format(prj_path))
    os.system("ls -al {0}".format(prj_path))

    # set prj_gen_path
    os.environ['PRJ_GEN_PATH'] = prj_path

    # find bsp path
    real_bsp_path = None
    for dir in os.listdir("/rt-thread/rt-thread-bsp"):
        if dir.find("sdk-bsp") != -1:
            real_bsp_path = os.path.join("/rt-thread/rt-thread-bsp", dir)
            logging.info("bsp path : {0}".format(real_bsp_path))
            break
    if real_bsp_path is None:
        logging.error("can't find bsp path, please check it!")
    board_path = "/RT-ThreadStudio/repo/Extract/Board_Support_Packages/RealThread/board/0.1.1/"
    do_copy_folder(real_bsp_path, board_path)
    gen_bsp_sdk_json(board_path, "/rt-thread/sdk-index/",
                     "/rt-thread/workspace/")
    # gen test case
    gen_sdk_test_case("bsp_chips.json", "mcu_config")

    os.system("python sdk_test_case.py")

    exit(0)
Exemple #13
0
def get_rt_thread_source_code():
    try:
        with open(r"/rt-thread/sdk-index/RT-Thread_Source_Code/index.json",
                  "r") as f:
            sourcr_releases = json.loads(f.read())["releases"]
    except Exception as e:
        logging.error("\nError message : {0}.".format(e))
        sys.exit(1)

    nano_url = None
    released_url = None
    for release in sourcr_releases:
        if release["description"].find("Nano released 3.1.3") != -1:
            nano_url = release["url"]
        if release["description"].find("released v4.0.2") != -1:
            released_url = release["url"]
    if not nano_url:
        logging.error(
            "Can't find nano source url, please check RT-Thread_Source_Code/index.json file."
        )
        sys.exit(1)
    if not released_url:
        logging.error(
            "Can't find released source url, please check RT-Thread_Source_Code/index.json file."
        )
        sys.exit(1)

    execute_command("wget -nv -O /rt-thread/nano.zip {0}".format(nano_url))
    execute_command(
        "unzip {0} -d /rt-thread/rt-thread-src".format("/rt-thread/nano.zip"))
    execute_command("rm -rf /rt-thread/nano.zip")
    execute_command(
        "wget -nv -O /rt-thread/released.zip {0}".format(released_url))
    execute_command("unzip {0} -d /rt-thread/rt-thread-src".format(
        "/rt-thread/released.zip"))
    execute_command("rm -rf /rt-thread/released.zip")
Exemple #14
0
    def download_all_external_package(self, external_package_list):
        rt_studio_install_path = Path("/RT-ThreadStudio")
        rt_studio_repo_path = rt_studio_install_path.joinpath("repo/Extract")
        for package in external_package_list:
            if package["package_type"] == "RT-Thread_Source_Code":
                index_file_path = self.get_rtt_source_code_index_file_from_package(
                )
                url = self.get_url_from_index_file(index_file_path,
                                                   package["package_version"])
                if package["package_version"] == "latest":
                    before = os.getcwd()
                    cmd = 'git clone ' + url
                    logging.info(
                        rt_studio_repo_path.joinpath(
                            package["package_relative_path"]))
                    logging.info(cmd)
                    if self.is_in_linux:
                        if not rt_studio_repo_path.joinpath(
                                package["package_relative_path"]).exists():
                            os.makedirs(
                                rt_studio_repo_path.joinpath(
                                    package["package_relative_path"]))
                        os.chdir(
                            rt_studio_repo_path.joinpath(
                                package["package_relative_path"]))
                        execute_command(cmd)
                        os.chdir(before)
                else:
                    zip_name = url.split("/")[-1]
                    pack_folder = rt_studio_repo_path.joinpath(
                        package["package_relative_path"])
                    zip_path = pack_folder.joinpath(zip_name)

                    # create dir
                    os.makedirs(pack_folder)
                    cmd = "wget -nv -O " + str(zip_path.as_posix()) + " " + url
                    logging.info(cmd)
                    if self.is_in_linux:
                        execute_command(cmd)

                    cmd = "unzip " + str(zip_path.as_posix()) + " -d " + str(
                        pack_folder.as_posix())
                    logging.info(cmd)
                    if self.is_in_linux:
                        execute_command(cmd)
                    for dir in os.listdir(pack_folder):
                        if dir.find("sdk") != -1:
                            sdk_path = os.path.join(pack_folder, dir)
                            logging.debug("sdk path : {0}".format(sdk_path))
                            execute_command("mv {0}/* {1}".format(
                                sdk_path, pack_folder))
                            logging.debug(
                                "pack folder : {0}".format(pack_folder))
                            execute_command("rm -rf {0}".format(sdk_path))
                            break

                    cmd = "rm -rf " + str(zip_path.as_posix())
                    logging.info(cmd)
                    if self.is_in_linux:
                        execute_command(cmd)

            elif package["package_type"].strip() == "Chip_Support_Packages":
                index_file_path = self.get_csp_index_file_from_package(package)
                url = self.get_url_from_index_file(index_file_path,
                                                   package["package_version"])
                zip_name = url.split("/")[-1]
                pack_folder = rt_studio_repo_path.joinpath(
                    package["package_relative_path"])
                os.makedirs(pack_folder)
                zip_path = pack_folder.joinpath(zip_name)
                cmd = "wget -nv -O " + str(zip_path.as_posix()) + " " + url
                logging.info(cmd)
                if self.is_in_linux:
                    execute_command(cmd)

                cmd = "unzip " + str(zip_path.as_posix()) + " -d " + str(
                    pack_folder.as_posix())
                logging.info(cmd)
                if self.is_in_linux:
                    execute_command(cmd)
                for dir in os.listdir(pack_folder):
                    if dir.find("sdk") != -1:
                        sdk_path = os.path.join(pack_folder, dir)
                        logging.debug("sdk path : {0}".format(sdk_path))
                        execute_command("mv {0}/* {1}".format(
                            sdk_path, pack_folder))
                        logging.debug("pack folder : {0}".format(pack_folder))
                        execute_command("rm -rf {0}".format(sdk_path))
                        break

                cmd = "rm -rf " + str(zip_path.as_posix())
                logging.info(cmd)
                if self.is_in_linux:
                    execute_command(cmd)
            else:
                pass
Exemple #15
0
def main():
    init_logger()
    os.chdir("/rt-thread/sdk-index/tools/sdk_check")
    logging.info(execute_command("apt-get update && apt-get -y upgrade"))
    logging.info(execute_command("python -m pip install --upgrade pip"))
    logging.info(
        execute_command(
            "pip install pytest pytest-sugar pytest-html rt-thread-studio"))

    # get oss package
    execute_command(
        'wget -nv '
        'https://realthread-download.oss-cn-hangzhou.aliyuncs.com/rt-studio/backend/rt-studio-backend.zip'
    )
    execute_command("unzip rt-studio-backend.zip")
    result = execute_command("ls -al /rt-thread/sdk-index/tools/sdk_check")
    logging.info("ls -al /tools/sdk_check {0}".format(result))

    if os.path.exists("/rt-thread/sdk-index/tools/sdk_check/prj_gen"):
        execute_command("chmod 777 prj_gen")
    else:
        logging.error("can't find prj_gen!")
        sys.exit(1)

    result = execute_command("ls -al /rt-thread/sdk-index/tools/sdk_check")
    logging.debug("ls -al tools/sdk_check : {0}".format(result))

    # get update csp url
    try:
        with open('/rt-thread/sdk-index/tools/csp_update_url.json', "r") as f:
            sdk_url = json.loads(f.read())[0]
        logging.info("csp check test URL : {0}".format(sdk_url))
        exec_csp_test_case()
        sys.exit(0)
    except Exception as e:
        logging.warning("warning message : {0}.".format(e))

    # get update bsp url
    try:
        with open('/rt-thread/sdk-index/tools/bsp_update_url.json', "r") as f:
            sdk_url = json.loads(f.read())[0]
        logging.info("bsp check test URL : {0}".format(sdk_url))
        exec_bsp_test_case()
        sys.exit(0)
    except Exception as e:
        logging.error("Error message : {0}.".format(e))
        sys.exit(0)