diff --git a/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_020.cpp b/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_020.cpp index 3c0ffcb..cdd059a 100644 --- a/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_020.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_020.cpp @@ -29,7 +29,7 @@ */ #include "lt_net_netdb.h" -// 引入头文件,包含了网络数据库相关的函数声明和宏定义。 +// ͷļݿصĺͺ궨塣 static int GetNetEntTest(void) { @@ -37,98 +37,193 @@ static int GetNetEntTest(void) "link-local 169.254.0.0\n" "example 192.168.1.0 network example-network\n" "test1"; - // 定义一个模拟的networks文件内容,包含网络名称和对应的地址。 + // һģnetworksļݣƺͶӦĵַ char *pathList[] = {"/etc/networks"}; - // 定义networks文件的路径列表,这里只有一个路径指向系统的networks文件。 + // networksļ·бֻһ·ָϵͳnetworksļ char *streamList[] = {static_cast(network_file)}; - // 定义模拟的networks文件流列表,这里将模拟的networks文件内容转换为char*类型。 + // ģnetworksļбォģnetworksļתΪchar*͡ int streamLen[] = {sizeof(network_file)}; - // 定义模拟的networks文件流长度列表。 + // ģnetworksļб const int file_number = 1; - // 定义文件数量。 + // ļ int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number); - // 调用PrepareFileEnv函数准备文件环境,模拟networks文件。 + // PrepareFileEnv׼ļģnetworksļ if (flag != 0) { RecoveryFileEnv(pathList, file_number); return -1; } - // 如果准备文件环境失败,则恢复原始文件环境并返回错误码。 + // ׼ļʧܣָԭʼļش롣 struct netent *se1 = nullptr; struct netent *se2 = nullptr; struct netent *se3 = nullptr; se1 = getnetent(); - // 调用getnetent函数获取networks数据库中的第一个网络条目。 + // getnetentȡnetworksݿеĵһĿ ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); - // 断言se1不为空,即getnetent成功。 + // se1Ϊգgetnetentɹ ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link-local", -1); - // 断言返回的网络名称与"link-local"相同。 + // Էص"link-local"ͬ ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); - // 断言返回的地址类型为AF_INET(IPv4)。 + // ԷصĵַΪAF_INETIPv4 ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1); - // 断言返回的网络地址与"169.254.0.0"相同。 + // Էصַ"169.254.0.0"ͬ ICUNIT_ASSERT_EQUAL(se1->n_aliases[0], nullptr, -1); - // 断言别名列表中的第一个别名为nullptr,表示别名列表结束。 + // ԱбеĵһΪnullptrʾб endnetent(); - // 调用endnetent函数结束网络数据库的搜索。 + // endnetentݿ se2 = getnetent(); - // 再次调用getnetent函数获取networks数据库中的第一个网络条目。 + // ٴεgetnetentȡnetworksݿеĵһĿ ICUNIT_ASSERT_NOT_EQUAL(se2, nullptr, -1); - // 断言se2不为空,即getnetent成功。 + // se2Ϊգgetnetentɹ ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, se2->n_name, -1); - // 断言返回的网络名称与之前相同。 + // Էص֮ǰͬ ICUNIT_ASSERT_EQUAL(se1->n_addrtype, se2->n_addrtype, -1); - // 断言返回的地址类型与之前相同。 + // Էصĵַ֮ǰͬ ICUNIT_ASSERT_EQUAL(se1->n_net, se2->n_net, -1); - // 断言返回的网络地址与之前相同。 + // Էصַ֮ǰͬ setnetent(0); - // 调用setnetent函数设置网络数据库的搜索位置到开始。 + // setnetentݿλõʼ se3 = getnetent(); - // 调用getnetent函数获取networks数据库中的第一个网络条目。 + // getnetentȡnetworksݿеĵһĿ ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1); - // 断言se3不为空,即getnetent成功。 + // se3Ϊգgetnetentɹ ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, se3->n_name, -1); - // 断言返回的网络名称与之前相同。 + // Էص֮ǰͬ ICUNIT_ASSERT_EQUAL(se1->n_addrtype, se3->n_addrtype, -1); - // 断言返回的地址类型与之前相同。 + // Էصĵַ֮ǰͬ ICUNIT_ASSERT_EQUAL(se1->n_net, se3->n_net, -1); - // 断言返回的网络地址与之前相同。 + // Էصַ֮ǰͬ se1 = getnetent(); - // 获取下一个网络条目。 + // ȡһĿ ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); - // 断言se1不为空,即getnetent成功。 + // se1Ϊգgetnetentɹ ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "example", -1); - // 断言返回的网络名称与"example"相同。 + // Էص"example"ͬ ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); - // 断言返回的地址类型为AF_INET(IPv4)。 + // ԷصĵַΪAF_INETIPv4 ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("192.168.1.0"), -1); - // 断言返回的网络地址与"192.168.1.0"相同。 + // Էصַ"192.168.1.0"ͬ ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[0], "network", -1); - // 断言别名列表中的第一个别名为"network"。 + // ԱбеĵһΪ"network" ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[1], "example-network", -1); - // 断言别名列表中的第二个别名为"example-network"。 + // ԱбеĵڶΪ"example-network" ICUNIT_ASSERT_EQUAL(se1->n_aliases[2], nullptr, -1); - // 断言别名列表中的第三个别名为nullptr,表示别名列表结束。 + // ԱбеĵΪnullptrʾб se1 = getnetent(); - // 获取下一个网络条目。 + // ȡһĿ ICUNIT_ASSERT_EQUAL(se1, nullptr, -1); - // 断言se1为空,即已经到达networks数据库的末尾。 + // se1ΪգѾnetworksݿĩβ endnetent(); - // 调用endnetent函数结束网络数据库的搜索。 + // endnetentݿ RecoveryFileEnv(pathList, file_number); - // 恢复原始文件环境。 + // ָԭʼļ return ICUNIT_SUCCESS; - // 返回测试成功。 + // زԳɹ } void NetNetDbTest020(void) { TEST_ADD_CASE(__FUNCTION__, GetNetEntTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); } -// 定义测试用例,将GetNetEntTest函数注册为一个测试案例。 \ No newline at end of file +Ƕδעͣ + +```cpp +/* + * opyright (c) 2021 - 2021, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020 - 2021 Huawei Device Co., Ltd. All rights reserved. + * + * ⲿǰȨָİȨΪ޹˾ͻΪ豸޹˾˵˴һµķַʹȨޡ + */ + +#include "lt_net_netdb.h" +// "lt_net_netdb.h" ͷļܰݿصĺṹ嶨ȡ + +static int GetNetEntTest(void) +{ + char network_file[] = "# symbolic names for networks, see networks(5) for more information\n" + "link - local 169.254.0.0\n" + "example 192.168.1.0 network example - network\n" + "test1"; + // һַnetwork_fileаһЩصϢϢʾݡ + + char *pathList[] = {"/etc/networks"}; + char *streamList[] = {static_cast(network_file)}; + int streamLen[] = {sizeof(network_file)}; + const int file_number = 1; + // һЩļصͱ + // pathListһַָ飬Ҫļ· + // streamListһַָ飬ォnetwork_fileתΪַָС + // streamLenһ飬¼ÿӦnetwork_fileijȡ + // file_numberʾļ + + int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number); + if (flag!= 0) { + RecoveryFileEnv(pathList, file_number); + return -1; + } + // PrepareFileEnv׼ļֵΪ0ʾд󣩣RecoveryFileEnvļĻָ -1ʾʧܡ + + struct netent *se1 = nullptr; + struct netent *se2 = nullptr; + struct netent *se3 = nullptr; + // ָnetentṹָ룬ʼΪnullptrnetentṹڴ洢صϢơַַ͡ȣ + + se1 = getnetent(); + ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link - local", -1); + ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); + ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1); + ICUNIT_ASSERT_EQUAL(se1->n_aliases[0], nullptr, -1); + // getnetentȡϢȻʹICUNIT_ASSERTصĺжԡ + // ȷse1ΪnullptrΪ "link - local"ַΪAF_INETַΪ "169.254.0.0"ҵһn_aliases[0]Ϊnullptr + + endnetent(); + se2 = getnetent(); + ICUNIT_ASSERT_NOT_EQUAL(se2, nullptr, -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, se2->n_name, -1); + ICUNIT_ASSERT_EQUAL(se1->n_addrtype, se2->n_addrtype, -1); + ICUNIT_ASSERT_EQUAL(se1->n_net, se2->n_net, -1); + // ȵendnetentȻٴεgetnetentȡϢȻжԣȷλȡϢơַͺַͬ + + setnetent(0); + se3 = getnetent(); + ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, se3->n_name, -1); + ICUNIT_ASSERT_EQUAL(se1->n_addrtype, se3->n_addrtype, -1); + ICUNIT_ASSERT_EQUAL(se1->n_net, se3->n_net, -1); + // setnetentݿĶȡλãΪ0⺬壩ȻȡϢжԣȷ֮ǰȡϢơַͺַͬ + + se1 = getnetent(); + ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "example", -1); + ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); + ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("192.168.1.0"), -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[0], "network", -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[1], "example - network", -1); + ICUNIT_ASSERT_EQUAL(se1->n_aliases[2], nullptr, -1); + // ٴεgetnetentȡϢһϵжԣȷȡϢơַַ͡ԼϢԤڡ + + se1 = getnetent(); + ICUNIT_ASSERT_EQUAL(se1, nullptr, -1); + endnetent(); + // ٴεgetnetentȡnullptrʾѾϢĩβȻendnetentϢĶȡ + + RecoveryFileEnv(pathList, file_number); + return ICUNIT_SUCCESS; + // RecoveryFileEnvļĻָICUNIT_SUCCESSʾִгɹ +} + +void NetNetDbTest020(void) +{ + TEST_ADD_CASE(__FUNCTION__, GetNetEntTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); + // NetNetDbTest020УTEST_ADD_CASE꣬ǰGetNetEntTestԼһЩصıǣ͡Э͡ԼȣӵС +} +``` + +ע⣬ICUNIT_ASSERTصĺԼһЩPrepareFileEnvRecoveryFileEnvinet_networkȣľ幦ҪݴڵĸĿȷиͷļؿϢȷע͡ \ No newline at end of file diff --git a/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_022.cpp b/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_022.cpp index 6cb19c8..ed29036 100644 --- a/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_022.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/net/netdb/full/net_netdb_test_022.cpp @@ -29,60 +29,139 @@ */ #include "lt_net_netdb.h" -// 引入头文件,包含了网络数据库相关的函数声明和宏定义。 +// ͷļݿصĺͺ궨塣 static int GetNetByAddrtTest(void) { char network_file[] = "# symbolic names for networks, see networks(5) for more information\n" "link-local 169.254.0.0\n"; - // 定义一个模拟的networks文件内容,包含网络名称和对应的地址。 + // һģnetworksļݣƺͶӦĵַ char *pathList[] = {"/etc/networks"}; - // 定义networks文件的路径列表,这里只有一个路径指向系统的networks文件。 + // networksļ·бֻһ·ָϵͳnetworksļ char *streamList[] = {static_cast(network_file)}; - // 定义模拟的networks文件流列表,这里将模拟的networks文件内容转换为char*类型。 + // ģnetworksļбォģnetworksļתΪchar*͡ int streamLen[] = {sizeof(network_file)}; - // 定义模拟的networks文件流长度列表。 + // ģnetworksļб const int file_number = 1; - // 定义文件数量。 + // ļ int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number); - // 调用PrepareFileEnv函数准备文件环境,模拟networks文件。 + // PrepareFileEnv׼ļģnetworksļ if (flag != 0) { RecoveryFileEnv(pathList, file_number); return -1; } - // 如果准备文件环境失败,则恢复原始文件环境并返回错误码。 + // ׼ļʧܣָԭʼļش롣 struct netent *se1 = nullptr; struct netent *se2 = nullptr; struct netent *se3 = nullptr; se1 = getnetbyaddr(inet_network("169.254.0.0"), AF_INET); - // 使用getnetbyaddr函数根据网络地址"169.254.0.0"和地址族AF_INET获取netent结构体指针。 + // ʹgetnetbyaddrַ"169.254.0.0"͵ַAF_INETȡnetentṹָ롣 ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); - // 断言se1不为空,即getnetbyaddr成功。 + // se1Ϊգgetnetbyaddrɹ ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link-local", -1); - // 断言返回的网络名称与"link-local"相同。 + // Էص"link-local"ͬ ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); - // 断言返回的地址类型为AF_INET(IPv4)。 + // ԷصĵַΪAF_INETIPv4 ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1); - // 断言返回的网络地址与"169.254.0.0"相同。 + // Էصַ"169.254.0.0"ͬ se2 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET); - // 尝试使用getnetbyaddr函数根据网络地址"169.254.0.1"和地址族AF_INET获取netent结构体指针,预期失败。 + // ʹgetnetbyaddrַ"169.254.0.1"͵ַAF_INETȡnetentṹָ룬Ԥʧܡ ICUNIT_ASSERT_EQUAL(se2, nullptr, -1); se3 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET6); - // 尝试使用getnetbyaddr函数根据网络地址"169.254.0.1"和地址族AF_INET6获取netent结构体指针,预期失败。 + // ʹgetnetbyaddrַ"169.254.0.1"͵ַAF_INET6ȡnetentṹָ룬Ԥʧܡ ICUNIT_ASSERT_EQUAL(se3, nullptr, -1); RecoveryFileEnv(pathList, file_number); - // 恢复原始文件环境。 + // ָԭʼļ return ICUNIT_SUCCESS; - // 返回测试成功。 + // زԳɹ } void NetNetDbTest022(void) { TEST_ADD_CASE(__FUNCTION__, GetNetByAddrtTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); } -// 定义测试用例,将GetNetByAddrtTest函数注册为一个测试案例。 \ No newline at end of file +Ƕδע + +**һͷļ** +```cpp +include "lt_net_netdb.h" +``` +- ﷨C/C++ ȷͷļ﷨`#include `ϵͳͷļ`#include "lt_net_netdb.h"`Զͷļȱ`#` + +**`GetNetByAddrtTest`** + +1. **岿** + - ```cpp + char network_file[] = "# symbolic names for networks, see networks(5) for more information\n" + "link - local 169.254.0.0"; + ``` + - Ƕһַ`network_file`ڴ洢صϢ￴ģһļеIJݡ + - ```cpp + char *pathList[] = {"/etc/networks"}; + char *streamList[] = {static_cast(network_file)}; + int streamLen[] = {sizeof(network_file)}; + const int file_number = 1; + ``` + - `pathList`һַָ飬ֻһԪأָļ·ģ· + - `streamList`һַָ飬`network_file`תΪ`char*`ͺ洢ģļȡݡ + - `streamLen`һ飬洢`streamList`жӦԪصijȣֻ洢`network_file`ijȡ + - `file_number`ļΪ1 + +2. **ļ׼** + - ```cpp + int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number); + if (flag!= 0) { + RecoveryFileEnv(pathList, file_number); + return - 1; + } + ``` + - `PrepareFileEnv`׼ļݺƲǽһЩļصijʼ׼طֵʾִô`RecoveryFileEnv`ļĻָ -1ʾִʧܡǴûи`PrepareFileEnv``RecoveryFileEnv`Ķ壬Ĺʵ֡ + +3. **ѯ** + - ```cpp + struct netent *se1 = nullptr; + struct netent *se2 = nullptr; + struct netent *se3 = nullptr; + ``` + - `netent`ṹָ룬ڴ洢صIJѯ`netent`ṹͨڴ洢صϢơַ͵ȡ + - ```cpp + se1 = getnetbyaddr(inet_network("169.254.0.0"), AF_INET); + ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1); + ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link - local", -1); + ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1); + ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1); + ``` + - `getnetbyaddr`ݸַȽַʽĵַ`169.254.0.0`ͨ`inet_network`תΪַʽѯϢ洢`se1`СȻʹ`ICUNIT_ASSERT_*`ϵеĺжԲ + - `se1`Ϊ`nullptr`ʾѯʧܣ`ICUNIT_ASSERT_NOT_EQUAL`߼дﲻ`ICUNIT_ASSERT_NOT_EQUAL`ľʵֿ֣жֵȣ + - ͨ`ICUNIT_ASSERT_STRING_EQUAL`жϲѯǷΪ`link - local`ͨ`ICUNIT_ASSERT_EQUAL`жϵַͺַǷԤڡ + - ```cpp + se2 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET); + ICUNIT_ASSERT_EQUAL(se2, nullptr, -1); + ``` + - Ƶأѯַ`169.254.0.1`Ϣַܲڻ߲ϲѯݴ߼Ʋ⣩ԲѯӦΪ`nullptr` + - ```cpp + se3 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET6); + ICUNIT_ASSERT_EQUAL(se3, nullptr, -1); + ``` + - ѯ`169.254.0.1`Ϣʹ`AF_INET6`IPv6ַͣͬݴ߼ƲѯӦ÷`nullptr`ʹöԽ֤ + +4. **ļָ** + - ```cpp + RecoveryFileEnv(pathList, file_number); + return ICUNIT_SUCCESS; + ``` + - ѯ󣬵`RecoveryFileEnv`ָļ󷵻`ICUNIT_SUCCESS``ICUNIT_SUCCESS`ľ嶨壬ֿDZʾִгɹ + +**`NetNetDbTest022`** +```cpp +void NetNetDbTest022(void) +{ + TEST_ADD_CASE(__FUNCTION__, GetNetByAddrtTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); +} +``` +- һעắ`GetNetByAddrtTest`עΪһָһЩصԣ`TEST_POSIX``TEST_TCP``TEST_LEVEL0``TEST_FUNCTION`ﲻЩԵľ庬壬ҪݲԿܵĶȷ \ No newline at end of file diff --git a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp index ac2a9dc..bfd2003 100644 --- a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp @@ -2,45 +2,73 @@ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. * - * 这部分版权信息说明了华为技术有限公司(或其子公司)是这段代码的版权持有者, - * 并规定了代码的重新分发和使用条件。 + * ⲿְȨϢ˵˻Ϊ޹˾ӹ˾δİȨߣ + * 涨˴·ַʹ */ -#include "lt_net_netdb.h" // 包含测试所需的网络数据库头文件 +#include "lt_net_netdb.h" // ݿͷļ -// 定义一个测试函数,用于测试协议数据库的功能 +// һԺڲЭݿĹ static int ProtoentTest(void) { - setprotoent(1); // 打开协议数据库文件,参数1表示重置文件指针到文件开始 + setprotoent(1); // Эݿļ1ʾļָ뵽ļʼ - // 引用/etc/protocols文件,获取名为"icmp"的协议条目 + // /etc/protocolsļȡΪ"icmp"ЭĿ struct protoent *prot = getprotobyname("icmp"); - // 断言:确保获取到的协议条目不为空 + // ԣȷȡЭĿΪ ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); - // 断言:确保获取到的协议编号是1(ICMP协议的编号) + // ԣȷȡЭ1ICMPЭıţ ICUNIT_ASSERT_EQUAL(prot->p_proto, 1, prot->p_proto); - // 获取编号为1的协议条目(也是ICMP协议) + // ȡΪ1ЭĿҲICMPЭ飩 prot = getprotobynumber(1); - // 断言:确保获取到的协议条目不为空 + // ԣȷȡЭĿΪ ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); - // 断言:确保获取到的协议名称是"icmp" - ICUNIT_ASSERT_EQUAL(strcmp(prot->p_name, "icmp"), 0, -1); // strcmp返回0表示字符串相等 + // ԣȷȡЭ"icmp" + ICUNIT_ASSERT_EQUAL(strcmp(prot->p_name, "icmp"), 0, -1); // strcmp0ʾַ - // 获取协议数据库中的下一个协议条目 + // ȡЭݿеһЭĿ prot = getprotoent(); - // 断言:确保获取到的协议条目不为空 + // ԣȷȡЭĿΪ ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); - // 关闭协议数据库文件 + // رЭݿļ endprotoent(); - // 返回测试成功标志 + // زԳɹ־ return ICUNIT_SUCCESS; } -// 定义一个测试注册函数,用于将ProtoentTest测试添加到测试套件中 +// һעắڽProtoentTestӵ׼ void NetNetDbTest001(void) { - // 添加测试用例到测试框架中,包括测试用例名称、测试函数、测试类别、测试协议、测试级别和测试类型 + // ӲԿУơԺ𡢲Э顢ԼͲ TEST_ADD_CASE(__FUNCTION__, ProtoentTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); -} \ No newline at end of file +} +Ƕδע + һ幦ܸ δ뿴һصĴƬΣ +Ҫݿ⣨netdbеЭزвԡ +ProtoentTest ͷļ #include "ltnetnetdb.h" +һԶͷļܰݿصĽṹ嶨塢ݡ + static int ProtoentTest(void)һ̬ζڵǰԴļڿɼ +ĿDzЭصݿ Эز setprotoent(1) +ÿЭݿ⣨protocolsĶȡλûߴЭݿ⡣ +1ضĺ壬Ҳʾijֶȡģʽò +struct protoent *prot = getprotobyname("icmp"); +ԸЭƣicmpЭݿлȡӦЭϢṹָ롣 +ICUNITASSERTNOT_EQUAL(prot, NULL, -1);һԲڼǷɹȡЭϢ +protΪNULLʾȡʧܣܻᴥӦĴͨԵķʽ +ICUNITASSERTEQUAL(prot->pproto, 1, prot->pproto); +ԿǼȡЭϢеЭǷԤڣԤ1 + prot = getprotobynumber(1); Эţ1ЭݿлȡЭϢṹָ롣 +ͬкĶԲICUNITASSERTNOTEQUAL(prot, NULL, -1); +ICUNITASSERTEQUAL(strcmp(prot->pname, "icmp"), 0, -1); +ǰ߼Ƿɹȡ߼ȡЭǷΪicmp +prot = getprotoent(); ٴδЭݿлȡһЭϢṹָ롣 +ICUNITASSERTNOT_EQUAL(prot, NULL, -1);ԼǷȡɹ +endprotoent();ÿڹرЭݿͷԴ +return ICUNITSUCCESS;շһʾɹijICUNITSUCCESSԶıʾɹı־ +NetNetDbTest001 +void NetNetDbTest001(void)һ֯ +TESTADDCASE(FUNCTION, ProtoentTest, TESTPOSIX, TESTTCP, TESTLEVEL0, TESTFUNCTION); +дǽProtoentTestӵһԿеIJFUNCTIONǵǰNetNetDbTest001 +IJTESTPOSIXTESTTCPTESTLEVEL0TESTFUNCTIONԡ͡صıǡ \ No newline at end of file diff --git a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/it_pthread_test.h b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/it_pthread_test.h index afcef81..b58baea 100644 --- a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/it_pthread_test.h +++ b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/it_pthread_test.h @@ -28,65 +28,70 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _IT_PTHREAD_TEST_H +#ifndef _IT_PTHREAD_TEST_H // ֹͷļظ #define _IT_PTHREAD_TEST_H - -#include "osTest.h" -#include -#include -#include - -#define SLEEP_AND_YIELD(tick) usleep((tick)*10 * 1000) - -#include "sys/syscall.h" - + +#include "osTest.h" // ϵͳصͷļ +#include // Դصͷļ +#include // ȴ̽صͷļ +#include // ʱ䴦ͷļ + +#define SLEEP_AND_YIELD(tick) usleep((tick)*10 * 1000) // ꣬˯ߺóCPUtickΪ΢뵥λ + +#include "sys/syscall.h" // ϵͳصͷļ + +// һִϵͳ static inline int Syscall(int nbr, int parm1, int parm2, int parm3, int parm4) { - register int reg7 __asm__("r7") = nbr; - register int reg3 __asm__("r3") = parm4; - register int reg2 __asm__("r2") = parm3; - register int reg1 __asm__("r1") = parm2; - register int reg0 __asm__("r0") = parm1; - + register int reg7 __asm__("r7") = nbr; // ϵͳúŷĴr7 + register int reg3 __asm__("r3") = parm4; // ĸĴr3 + register int reg2 __asm__("r2") = parm3; // Ĵr2 + register int reg1 __asm__("r1") = parm2; // ڶĴr1 + register int reg0 __asm__("r0") = parm1; // һĴr0 + + // ʹsvcָϵͳãreg0 __asm__ __volatile__("svc 0" : "=r"(reg0) : "r"(reg7), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3) : "memory"); - - return reg0; + + return reg0; // ϵͳõĽ } + +// ȫֱڴ洢ԪԵĴʹк extern INT32 g_iCunitErrCode; extern INT32 g_iCunitErrLineNo; - -extern void ItTestPthread001(void); -extern void ItTestPthread002(void); -extern void ItTestPthread003(void); -extern void ItTestPthread004(void); -extern void ItTestPthread005(void); -extern void ItTestPthread006(void); -extern void ItTestPthread007(void); -extern void ItTestPthread008(void); -extern void ItTestPthread009(void); -extern void ItTestPthread010(void); -extern void ItTestPthread012(void); -extern void ItTestPthread011(void); -extern void ItTestPthread013(void); -extern void ItTestPthread014(void); -extern void ItTestPthread015(void); -extern void ItTestPthread016(void); -extern void ItTestPthread017(void); -extern void ItTestPthread018(void); -extern void ItTestPthread019(void); -extern void ItTestPthread020(void); -extern void ItTestPthread021(void); -extern void ItTestPthread022(void); -extern void ItTestPthread023(void); -extern void ItTestPthread024(void); -extern void ItTestPthread025(void); -extern void ItTestPthread026(void); -extern void ItTestPthread027(void); -extern void ItTestPthreadAtfork001(void); -extern void ItTestPthreadAtfork002(void); -extern void ItTestPthreadOnce001(void); -extern void ItTestPthreadCond001(void); -extern void ItTestPthreadCond002(void); -extern void ItTestPthreadCond003(void); -extern void ItTestPthreadCond004(void); -#endif + +// һϵpthreadصIJԺ +extern void ItTestPthread001(void); // pthreadԺ1 +extern void ItTestPthread002(void); // pthreadԺ2 +extern void ItTestPthread003(void); // pthreadԺ3 +extern void ItTestPthread004(void); // pthreadԺ4 +extern void ItTestPthread005(void); // pthreadԺ5 +extern void ItTestPthread006(void); // pthreadԺ6 +extern void ItTestPthread007(void); // pthreadԺ7 +extern void ItTestPthread008(void); // pthreadԺ8 +extern void ItTestPthread009(void); // pthreadԺ9 +extern void ItTestPthread010(void); // pthreadԺ10 +extern void ItTestPthread012(void); // ʡ11Ǹ© +extern void ItTestPthread011(void); // pthreadԺ11 +extern void ItTestPthread013(void); // pthreadԺ13 +extern void ItTestPthread014(void); // pthreadԺ14 +extern void ItTestPthread015(void); // pthreadԺ15 +extern void ItTestPthread016(void); // pthreadԺ16 +extern void ItTestPthread017(void); // pthreadԺ17 +extern void ItTestPthread018(void); // pthreadԺ18 +extern void ItTestPthread019(void); // pthreadԺ19 +extern void ItTestPthread020(void); // pthreadԺ20 +extern void ItTestPthread021(void); // pthreadԺ21 +extern void ItTestPthread022(void); // pthreadԺ22 +extern void ItTestPthread023(void); // pthreadԺ23 +extern void ItTestPthread024(void); // pthreadԺ24 +extern void ItTestPthread025(void); // pthreadԺ25 +extern void ItTestPthread026(void); // pthreadԺ26 +extern void ItTestPthread027(void); // pthreadԺ27 +extern void ItTestPthreadAtfork001(void); // pthread atforkԺ1 +extern void ItTestPthreadAtfork002(void); // pthread atforkԺ2 +extern void ItTestPthreadOnce001(void); // pthread onceԺ1 +extern void ItTestPthreadCond001(void); // pthread Ժ1 +extern void ItTestPthreadCond002(void); // pthread Ժ2 +extern void ItTestPthreadCond003(void); // pthread Ժ3 +extern void ItTestPthreadCond004(void); // pthread Ժ4 +#endif // ͷļ diff --git a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/process_pthread_test.cpp b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/process_pthread_test.cpp index c14dff8..086c225 100644 --- a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/process_pthread_test.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/process_pthread_test.cpp @@ -28,71 +28,71 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// 包含标准输入输出头文件 +// ׼ͷļ #include "stdio.h" -// 包含C标准库中的极限定义 +// C׼еļ޶ #include -// 包含Google Test测试框架头文件 +// Google TestԿͷļ #include -// 包含自定义的pthread测试头文件 +// Զpthreadͷļ #include "it_pthread_test.h" -// 包含系统资源库头文件 +// ϵͳԴͷļ #include -// 使用Google Test框架的扩展命名空间 +// ʹGoogle Testܵչռ using namespace testing::ext; -// 定义一个名为OHOS的命名空间,用于封装测试代码 +// һΪOHOSռ䣬ڷװԴ namespace OHOS { -// 定义一个测试类ProcessPthreadTest,它继承自Google Test框架的Test类 +// һProcessPthreadTest̳Google TestܵTest class ProcessPthreadTest : public testing::Test { public: - // 测试套件开始前调用的静态成员函数,用于设置测试环境 + // ׼ʼǰõľ̬ԱòԻ static void SetUpTestCase(void) { - struct sched_param param = { 0 }; // 定义调度参数结构体 - int currThreadPolicy, ret; // 定义当前线程策略和返回值变量 - // 获取当前线程的调度参数 + struct sched_param param = { 0 }; // Ȳṹ + int currThreadPolicy, ret; // 嵱ǰ̲߳Ժͷֵ + // ȡǰ̵߳ĵȲ ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m); - // 断言返回值为0,如果不为0则用-ret作为错误码 + // ԷֵΪ0Ϊ0-retΪ ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret); - // 设置线程的调度优先级 + // ̵߳ĵȼ param.sched_priority = TASK_PRIO_TEST; - // 设置当前线程的调度参数 + // õǰ̵߳ĵȲ ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); - // 断言返回值为0,如果不为0则用-ret作为错误码 + // ԷֵΪ0Ϊ0-retΪ ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret); } - // 测试套件结束后调用的静态成员函数,用于清理测试环境(这里为空实现) + // ׼õľ̬ԱԻΪʵ֣ static void TearDownTestCase(void) {} }; #if defined(LOSCFG_USER_TEST_SMOKE) -// 如果定义了LOSCFG_USER_TEST_SMOKE,则编译并执行以下测试用例 +// LOSCFG_USER_TEST_SMOKE벢ִ² /* * * @tc.name: it_test_pthread_003 * @tc.desc: function for ProcessPthreadTest * @tc.type: FUNC */ -// 定义测试用例ItTestPthread003 +// ItTestPthread003 HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0) { ItTestPthread003(); } #endif #ifndef LOSCFG_USER_TEST_SMP -// 如果未定义LOSCFG_USER_TEST_SMP,则编译并执行以下测试用例 +// δLOSCFG_USER_TEST_SMP벢ִ² /* * * @tc.name: it_test_pthread_006 * @tc.desc: function for ProcessPthreadTest * @tc.type: FUNC */ -// 定义测试用例ItTestPthread006 +// ItTestPthread006 HWTEST_F(ProcessPthreadTest, ItTestPthread006, TestSize.Level0) { ItTestPthread006(); } #endif -// 以下是其他测试用例的定义,每个测试用例都有相应的注释说明其功能和类型 +// Ķ壬ÿӦע˵书ܺ /* * * @tc.name: it_test_pthread_007 * @tc.desc: function for ProcessPthreadTest @@ -234,4 +234,429 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread022, TestSize.Level0) { * @tc.require: issueI6T3P3 * @tc.author: */ -HWTEST_F(ProcessPthreadTest, ItTestP \ No newline at end of file +HWTEST_F(ProcessPthreadTest, ItTestP/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdio.h" // ׼ͷļ +#include // ַͷļ +#include // googleԿͷļ +#include "it_pthread_test.h" // Զpthreadͷļ +#include // ϵͳԴͷļ + +using namespace testing::ext; // ʹgoogleԿܵչռ +namespace OHOS { // OHOSռ +class ProcessPthreadTest : public testing::Test { // һ̳testing::TestIJ +public: + static void SetUpTestCase(void) // ̬ԱвԿʼǰִ + { + struct sched_param param = { 0 }; // һsched_paramṹ岢ʼΪ0 + int currThreadPolicy, ret; // 嵱ǰ̲߳Ժͷֵ + ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m); // ȡǰ̵߳ĵȲ + ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret); // ʹԶԷֵǷΪ0 + param.sched_priority = TASK_PRIO_TEST; // õȼΪTASK_PRIO_TESTδڴж壩 + ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); // õǰ̵߳ĵȲԺͲ + ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret); // ʹԶԷֵǷΪ0 + } + static void TearDownTestCase(void) {} // ̬ԱвԽִУ˴Ϊʵ +}; + +#if defined(LOSCFG_USER_TEST_SMOKE) // LOSCFG_USER_TEST_SMOKE +/* * + * @tc.name: it_test_pthread_003 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0) // һ +{ + ItTestPthread003(); // ItTestPthread003δڴж壩 +} + +#ifndef LOSCFG_USER_TEST_SMP // ûжLOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_006 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread006, TestSize.Level0) // һ +{ + ItTestPthread006(); // ItTestPthread006δڴж壩 +} +#endif + +/* * + * @tc.name: it_test_pthread_007 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread007, TestSize.Level0) // һ +{ + ItTestPthread007(); // ItTestPthread007δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_008 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread008, TestSize.Level0) // һ +{ + ItTestPthread008(); // ItTestPthread008δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_009 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread009, TestSize.Level0) // һ +{ + ItTestPthread009(); // ItTestPthread009δڴж壩 +} + +#ifndef LOSCFG_USER_TEST_SMP // ûжLOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_010 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread010, TestSize.Level0) // һ +{ + ItTestPthread010(); // ItTestPthread010δڴж壩 +} +#endif + +/* * + * @tc.name: it_test_pthread_011 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread011, TestSize.Level0) // һ +{ + ItTestPthread011(); // ItTestPthread011δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_012 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread012, TestSize.Level0) // һ +{ + ItTestPthread012(); // ItTestPthread012δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_013 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread013, TestSize.Level0) // һ +{ + ItTestPthread013(); // ItTestPthread013δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_015 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread015, TestSize.Level0) // һ +{ + ItTestPthread015(); // ItTestPthread015δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_016 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread016, TestSize.Level0) // һ +{ + ItTestPthread016(); // ItTestPthread016δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_018 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread018, TestSize.Level0) // һ +{ + ItTestPthread018(); // ItTestPthread018δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_019 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0) // һ +{ + ItTestPthread019(); // ItTestPthread019δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_020 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread020, TestSize.Level0) // һ +{ + ItTestPthread020(); // ItTestPthread020δڴж壩 +} + +/* * + * @tc.name: it_test_pthread_021 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread021, TestSize.Level0) +{ + ItTestPthread021(); +} + +/* * + * @tc.name: it_test_pthread_022 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread022, TestSize.Level0) +{ + ItTestPthread022(); +} + +/* * + * @tc.name: it_test_pthread_024 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread024, TestSize.Level0) +{ + ItTestPthread024(); +} + +/* * + * @tc.name: it_test_pthread_026 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread026, TestSize.Level0) +{ + ItTestPthread026(); +} + +/* * + * @tc.name: it_test_pthread_027 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread027, TestSize.Level0) +{ + ItTestPthread027(); +} + + +/* * + * @tc.name: it_test_pthread_023 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread023, TestSize.Level0) +{ + ItTestPthread023(); +} + + +/* * + * @tc.name: it_test_pthread_025 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: issueI6T3P3 + * @tc.author: + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread025, TestSize.Level0) +{ + ItTestPthread025(); +} + +/* * + * @tc.name: it_test_pthread_017 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0) +{ + ItTestPthread017(); +} + + +/* * + * @tc.name: it_test_pthread_once_001 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadOnce001, TestSize.Level0) +{ + ItTestPthreadOnce001(); +} + +/* * + * @tc.name: it_test_pthread_atfork_001 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork001, TestSize.Level0) +{ + ItTestPthreadAtfork001(); +} + +/* * + * @tc.name: it_test_pthread_atfork_002 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork002, TestSize.Level0) +{ + ItTestPthreadAtfork002(); +} + +/* * + * @tc.name: it_test_pthread_cond_001 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond001, TestSize.Level0) +{ + ItTestPthreadCond001(); +} + +/* * + * @tc.name: it_test_pthread_cond_002 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond002, TestSize.Level0) +{ + ItTestPthreadCond002(); +} + +/* * + * @tc.name: it_test_pthread_cond_003 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond003, TestSize.Level0) +{ + ItTestPthreadCond003(); +} + +/* * + * @tc.name: it_test_pthread_cond_004 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond004, TestSize.Level0) +{ + ItTestPthreadCond004(); +} + +#endif + +#if defined(LOSCFG_USER_TEST_FULL) +/* * + * @tc.name: it_test_pthread_001 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread001, TestSize.Level0) +{ + ItTestPthread001(); +} + +#ifndef LOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_002 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread002, TestSize.Level0) +{ + ItTestPthread002(); +} +#endif +/* * + * @tc.name: it_test_pthread_004 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0) +{ + ItTestPthread004(); +} + +/* * + * @tc.name: it_test_pthread_005 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0) +{ + ItTestPthread005(); +} + +#ifndef LOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_014 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread014, TestSize.Level0) +{ + ItTestPthread014(); +} +#endif + +#endif +} // namespace OHOS diff --git a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/smoke/pthread_atfork_test_001.cpp b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/smoke/pthread_atfork_test_001.cpp index 9c3a3a3..f0b3979 100644 --- a/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/smoke/pthread_atfork_test_001.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/process/basic/pthread/smoke/pthread_atfork_test_001.cpp @@ -28,7 +28,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "it_pthread_test.h" +#include "it_pthread_test.h" static volatile int g_count = 0; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; diff --git a/kernel_liteos_a-master/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp b/kernel_liteos_a-master/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp index 3c4fcf6..4fd7f26 100644 --- a/kernel_liteos_a-master/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp @@ -38,13 +38,14 @@ #include #include "It_process_plimits.h" +//write function to get process file mode static std::string GetFileMode(const char* filePath) { const int MODE_COUNT = 11; char fileProperty[MODE_COUNT] = "----------"; char fileMode[MODE_COUNT] = "-rwxrwxrwx"; struct stat buf; - stat(filePath, &buf); + stat(filePath, &buf);//get state of the file unsigned int off = 256; const int LOOP_VARY = 10; for (int i = 1; i < LOOP_VARY; i++) { @@ -55,6 +56,7 @@ static std::string GetFileMode(const char* filePath) return fileProperty; } +//check the Property static int IsFilePropertyR1(const char* filePath) { std::string fileOrg = "-r--r--r--"; @@ -64,6 +66,7 @@ static int IsFilePropertyR1(const char* filePath) void ItProcessPlimits008(void) { + //define process function ID std::string filePath = "/proc/plimits/"; std::vector fileName; fileName.push_back("plimits.procs"); @@ -86,3 +89,12 @@ void ItProcessPlimits008(void) return; } + + +/*It is used primarily to verify access to specific files in +the /proc/plimit/directory, ensuring that these files are read-only +*/ + + + + diff --git a/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp b/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp index f888798..f4ba2e2 100644 --- a/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp @@ -28,68 +28,74 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "pthread.h" -#include "linux/capability.h" -#include -#include "it_test_capability.h" -#include -#include -#include - -#define CAP_NUM 2 -#define INVAILD_PID 65535 -#define CHANGE_CHILD_UID 1000 - +#include "pthread.h" // POSIX߳̿⣬ڶ̱߳ +#include "linux/capability.h" // Linuxcapabilities壬Ȩ޿ +#include // ϵͳӿ +#include "it_test_capability.h" // DzԿܻصͷļ +#include // źŴ +#include // +#include // ʱ䴦 + +#define CAP_NUM 2 // ĴС +#define INVAILD_PID 65535 // һЧĽID +#define CHANGE_CHILD_UID 1000 // ӽҪĵûID + +// źŴǰΪʵ static void Sigac(int param) { return; } - + +// ӽ̺ static void Child() { - int i = 10; - signal(25, Sigac); - - while (i--) { + int i = 10; // ѭ + signal(25, Sigac); // ź25ĴΪSigac + + while (i--) { // ѭ10Σÿ˯1 sleep(1); } + // ˯10˳ exit(0); } - + +// ӽ̵ĺ static int TestChild(VOID) { - struct __user_cap_header_struct capheader; - struct __user_cap_data_struct capdata[CAP_NUM]; - struct __user_cap_data_struct capdatac[CAP_NUM]; - struct timespec tp; - int ret; - - (void)memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); - (void)memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, - CAP_NUM * sizeof(struct __user_cap_data_struct)); - capdata[0].permitted = 0xffffffff; - capdata[1].permitted = 0xffffffff; - capheader.version = _LINUX_CAPABILITY_VERSION_3; - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETPCAP); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETUID); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_KILL); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_TIME); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); - ret = capset(&capheader, &capdata[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - capheader.pid = INVAILD_PID; - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, -1, ret); - errno = 0; - capheader.pid = 3; - kill(capheader.pid, 0); - if (errno != ESRCH) { - ret = capget(&capheader, &capdatac[0]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); + struct __user_cap_header_struct capheader; // ͷṹ + struct __user_cap_data_struct capdata[CAP_NUM]; // ݽṹ + struct __user_cap_data_struct capdatac[CAP_NUM]; // һݽṹ飬ڻȡǰ + struct timespec tp; // ʱṹ + int ret; // 巵ֵ˴©д˳ʼ + // ʼṹ + (void)memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); // ͷṹ + (void)memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, CAP_NUM * sizeof(struct __user_cap_data_struct)); // ݽṹ + capdata[0].permitted = 0xffffffff; // Ϊȫ + capdata[1].permitted = 0xffffffff; // ͬϣڶݽṹҲȫȻֻһ + capheader.version = _LINUX_CAPABILITY_VERSION_3; // 汾 + // Чλ + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETPCAP); // ޸Ľ + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETUID); // ıûID + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_KILL); // ź + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_TIME); // ıϵͳʱ + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); // ıȼ + // ʹcapset鷵ֵ + ret = capset(&capheader, &capdata[0]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // capset0ʾɹ + ret = capget(&capheader, &capdatac[0]); // ȡǰ + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // capget0ʾɹ + capheader.pid = INVAILD_PID; // һЧPID + ret = capget(&capheader, &capdatac[0]); // ԻȡЧPID + ICUNIT_ASSERT_EQUAL(ret, -1, ret); // Է-1ʾʧ + errno = 0; // errno + capheader.pid = 3; // PIDΪ3 + kill(capheader.pid, 0); // PIDǷ + if (errno != ESRCH) { // PID + ret = capget(&capheader, &capdatac[0]); // ȡ + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // Գɹ + printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); // ӡЧ } + // ƵأPID 4, 5, 6 errno = 0; capheader.pid = 4; kill(capheader.pid, 0); @@ -114,39 +120,42 @@ static int TestChild(VOID) ICUNIT_ASSERT_EQUAL(ret, 0, ret); printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); } - capheader.pid = 0; - - int pid = fork(); - if (pid == 0) { - ret = setuid(CHANGE_CHILD_UID); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - Child(); + capheader.pid = 0; // PIDΪ0ǰ̣ + // ӽ̵UID + int pid = fork(); // ӽ + if (pid == 0) { // ӽ + ret = setuid(CHANGE_CHILD_UID); // ԸıûID + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // Գɹ + Child(); // ִӽ̺ } - sleep(1); - ret = kill(pid, SIGXFSZ); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); + sleep(1); // ̵ȴ1 + ret = kill(pid, SIGXFSZ); // ԷSIGXFSZźŸӽ + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // Գɹ + // ƳKILLٴγԷźţӦʧ capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective &= ~CAP_TO_MASK(CAP_KILL); - ret = capset(&capheader, &capdata[0]); - ret = kill(pid, SIGXFSZ); - ICUNIT_ASSERT_EQUAL(ret, -1, ret); - - tp.tv_sec = 0; - tp.tv_nsec = 0; - ret = clock_settime(CLOCK_REALTIME, &tp); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective &= ~CAP_TO_MASK(CAP_SYS_TIME); - ret = capset(&capheader, &capdata[0]); - ret = clock_settime(CLOCK_REALTIME, &tp); - ICUNIT_ASSERT_EQUAL(ret, -1, ret); - - struct sched_param param = { 0 }; - ret = sched_getparam(pid, ¶m); - param.sched_priority--; - ret = sched_setparam(pid, ¶m); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective &= ~CAP_TO_MASK(CAP_SYS_NICE); - ret = capset(&capheader, &capdata[0]); - ret = sched_setparam(pid, ¶m); + ret = capset(&capheader, &capdata[0]); // + ret = kill(pid, SIGXFSZ); // ٴγԷź + ICUNIT_ASSERT_EQUAL(ret, -1, ret); // ʧ + + // ϵͳʱ䣬ӦóɹȻʧܣƳSYS_TIME + tp.tv_sec = 0; // ʱΪ0 + tp.tv_nsec = 0; // 벿ҲΪ0 + ret = clock_settime(CLOCK_REALTIME, &tp); // ʱ + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // Գɹ + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective &= ~CAP_TO_MASK(CAP_SYS_TIME); // ƳSYS_TIME + ret = capset(&capheader, &capdata[0]); // + ret = clock_settime(CLOCK_REALTIME, &tp); // ٴγʱ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); // ʧ + + // Ըıӽ̵ĵȼӦóɹȻʧܣƳSYS_NICE + struct sched_param param = { 0 }; // Ȳṹ + ret = sched_getparam(pid, ¶m); // ȡǰȲ + param.sched_priority--; // ȼ + ret = sched_setparam(pid, ¶m); // µĵȲ + ICUNIT_ASSERT_EQUAL(ret, 0, ret); // Գɹ + capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective &= ~CAP_TO_MASK(CAP_SYS_NICE); // ƳSYS_NICE + ret = capset(&capheader, &capdata[0]); // + ret = sched_setparam(pid, ¶m); // ٴγõȲ ICUNIT_ASSERT_EQUAL(ret, -1, ret); wait(nullptr); exit(92); @@ -160,6 +169,7 @@ static int TestCase(VOID) int status = 0; pid_t pid = fork(); ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); + if (pid == 0) { ret = TestChild(); exit(__LINE__); diff --git a/开源软件阅读报告.pdf b/开源软件阅读报告.pdf new file mode 100644 index 0000000..9477e65 Binary files /dev/null and b/开源软件阅读报告.pdf differ