• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <stdlib.h>
33 #include <errno.h>
34 #include "ohos_types.h"
35 #include "posix_test.h"
36 #include "los_config.h"
37 #include "kernel_test.h"
38 #include "log.h"
39 
40 /* *
41  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
42  * @param        : subsystem name is utils
43  * @param        : module name is utilsFile
44  * @param        : test suit name is PosixSysFuncTestSuite
45  */
46 LITE_TEST_SUIT(Posix, Posixsystem, PosixSysFuncTestSuite);
47 
48 
49 /* *
50  * @tc.setup     : setup for all testcases
51  * @return       : setup result, TRUE is success, FALSE is fail
52  */
PosixSysFuncTestSuiteSetUp(void)53 static BOOL PosixSysFuncTestSuiteSetUp(void)
54 {
55     return TRUE;
56 }
57 
58 /* *
59  * @tc.teardown  : teardown for all testcases
60  * @return       : teardown result, TRUE is success, FALSE is fail
61  */
PosixSysFuncTestSuiteTearDown(void)62 static BOOL PosixSysFuncTestSuiteTearDown(void)
63 {
64     printf("+Hello this is a System function test+\n");
65     return TRUE;
66 }
67 
68 /* *
69  * @tc.number    : SUB_KERNEL_POSIX_strerror_OPERATION_001
70  * @tc.name      : Memony operation for strerror test
71  * @tc.desc      : [C- SOFTWARE -0200]
72  */
73 LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTest | Level1)
74 {
75 #if (LOSCFG_LIBC_MUSL == 1)
76     for (int i = EPERM; i < EHWPOISON; i++) {
77         char *s = strerror(i);
78         ICUNIT_ASSERT_NOT_EQUAL(s, NULL, s);
79     }
80 
81     LOG("strerror(-1) = %s\n", strerror(-1));
82     ICUNIT_ASSERT_STRING_EQUAL(strerror(-1), "No error information", -1);
83     LOG("strerror(0) = %s\n", strerror(0));
84     ICUNIT_ASSERT_STRING_EQUAL(strerror(0), "No error information", 0);
85     LOG("strerror(2) = %s\n", strerror(2));
86     ICUNIT_ASSERT_STRING_EQUAL(strerror(2), "No such file or directory", 2);
87     LOG("strerror(10) = %s\n", strerror(10));
88     ICUNIT_ASSERT_STRING_EQUAL(strerror(10), "No child process", 10);
89 #endif
90 #if (LOSCFG_LIBC_NEWLIB == 1)
91     LOG("strerror(0) = %s\n", strerror(0));
92     ICUNIT_ASSERT_STRING_EQUAL(strerror(0), "Success", 0);
93     LOG("strerror(2) = %s\n", strerror(2));
94     ICUNIT_ASSERT_STRING_EQUAL(strerror(2), "No such file or directory", 2);
95     LOG("strerror(10) = %s\n", strerror(10));
96     ICUNIT_ASSERT_STRING_EQUAL(strerror(10), "No children", 10);
97 #endif
98 
99     return LOS_OK;
100 };
101 
PosixStrerrorTest()102 void PosixStrerrorTest()
103 {
104     LOG("begin PosixStrerrorTest....");
105     RUN_ONE_TESTCASE(testOsSysStrerror001);
106 
107     return;
108 }