1 #include <gtest/gtest.h> 2 #include <limits.h> 3 #include <sys/resource.h> 4 #include <sys/sysinfo.h> 5 #include <unistd.h> 6 7 using namespace testing::ext; 8 9 class ConfSysconfTest : public testing::Test { SetUp()10 void SetUp() override {} TearDown()11 void TearDown() override {} 12 }; 13 14 /** 15 * @tc.name: sysconf_001 16 * @tc.desc: Validate whether the sysconf interface correctly reports that the maximum number of user trace events is 17 * not available by checking if the value returned by sysconf(_SC_TRACE_USER_EVENT_MAX) is equal to -1. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(ConfSysconfTest, sysconf_001, TestSize.Level1) 21 { 22 int result = sysconf(_SC_TRACE_USER_EVENT_MAX); 23 EXPECT_EQ(-1, result); 24 } 25 26 /** 27 * @tc.name: sysconf_002 28 * @tc.desc: Validate whether the sysconf interface correctly returns the maximum number of thread-specific data keys by 29 * comparing the value returned by sysconf(_SC_THREAD_KEYS_MAX) with the predefined value PTHREAD_KEYS_MAX. 30 * @tc.type: FUNC 31 */ 32 HWTEST_F(ConfSysconfTest, sysconf_002, TestSize.Level1) 33 { 34 int pthreadKeyMax = sysconf(_SC_THREAD_KEYS_MAX); 35 EXPECT_EQ(pthreadKeyMax, PTHREAD_KEYS_MAX); 36 } 37 38 /** 39 * @tc.name: sysconf_003 40 * @tc.desc: Validate whether the sysconf interface correctly returns the clock ticks per second by comparing the value 41 * returned by sysconf(_SC_CLK_TCK) with the predefined value 100. 42 * @tc.type: FUNC 43 */ 44 HWTEST_F(ConfSysconfTest, sysconf_003, TestSize.Level1) 45 { 46 int result = sysconf(_SC_CLK_TCK); 47 EXPECT_EQ(100, result); 48 } 49 50 /** 51 * @tc.name: sysconf_004 52 * @tc.desc: Validate whether the sysconf interface correctly returns the maximum length of time zone names by comparing 53 * the value returned by sysconf(_SC_TZNAME_MAX) with the predefined value TZNAME_MAX. 54 * @tc.type: FUNC 55 */ 56 HWTEST_F(ConfSysconfTest, sysconf_004, TestSize.Level1) 57 { 58 int result = sysconf(_SC_TZNAME_MAX); 59 EXPECT_EQ(result, TZNAME_MAX); 60 } 61 62 /** 63 * @tc.name: sysconf_005 64 * @tc.desc: Check whether the system supports priority scheduling by verifying that the value returned by 65 * sysconf(_SC_PRIORITY_SCHEDULING) is -1. 66 * @tc.type: FUNC 67 */ 68 HWTEST_F(ConfSysconfTest, sysconf_005, TestSize.Level1) 69 { 70 int result = sysconf(_SC_PRIORITY_SCHEDULING); 71 EXPECT_EQ(-1, result); 72 } 73 74 /** 75 * @tc.name: sysconf_006 76 * @tc.desc: Validate whether the sysconf interface correctly returns the maximum number of real-time signals by 77 * comparing the value returned by sysconf(_SC_RTSIG_MAX) with the calculated result of _NSIG - 1 - 31 - 3. 78 * @tc.type: FUNC 79 */ 80 HWTEST_F(ConfSysconfTest, sysconf_006, TestSize.Level1) 81 { 82 int result = sysconf(_SC_SIGQUEUE_MAX); 83 EXPECT_EQ(-1, result); 84 } 85 86 /** 87 * @tc.name: sysconf_007 88 * @tc.desc: Validate whether the sysconf interface correctly returns the page size by comparing the value returned by 89 * sysconf(_SC_PAGE_SIZE) with the page size returned by the getpagesize() function. 90 * @tc.type: FUNC 91 */ 92 HWTEST_F(ConfSysconfTest, sysconf_007, TestSize.Level1) 93 { 94 int result = sysconf(_SC_PAGE_SIZE); 95 EXPECT_EQ(result, getpagesize()); 96 } 97 98 /** 99 * @tc.name: sysconf_008 100 * @tc.desc: Validate whether the sysconf interface correctly returns the maximum number of semaphores per semaphore 101 * identifier by comparing the value returned by sysconf(_SC_SEM_NSEMS_MAX) with the predefined value 102 * SEM_NSEMS_MAX. 103 * @tc.type: FUNC 104 */ 105 HWTEST_F(ConfSysconfTest, sysconf_008, TestSize.Level1) 106 { 107 int result = sysconf(_SC_SEM_NSEMS_MAX); 108 EXPECT_EQ(result, SEM_NSEMS_MAX); 109 } 110 111 /** 112 * @tc.name: sysconf_009 113 * @tc.desc: Validate whether the sysconf interface correctly returns the maximum number of weights available for 114 * sorting rules by comparing the value returned by sysconf(_SC_COLL_WEIGHTS_MAX) with the predefined value 115 * COLL_WEIGHTS_MAX. 116 * @tc.type: FUNC 117 */ 118 HWTEST_F(ConfSysconfTest, sysconf_009, TestSize.Level1) 119 { 120 int result = sysconf(_SC_COLL_WEIGHTS_MAX); 121 EXPECT_EQ(result, COLL_WEIGHTS_MAX); 122 } 123 124 /** 125 * @tc.name: sysconf_010 126 * @tc.desc: Validate whether the sysconf interface correctly returns the number of configured processors by comparing 127 * the value returned by sysconf(_SC_NPROCESSORS_CONF) with the number of processors returned by the 128 * get_nprocs function. 129 * @tc.type: FUNC 130 */ 131 HWTEST_F(ConfSysconfTest, sysconf_010, TestSize.Level1) 132 { 133 int result = sysconf(_SC_NPROCESSORS_CONF); 134 EXPECT_EQ(result, get_nprocs()); 135 }