1/* 2 * Copyright (C) 2024 HiHope Open Source Organization. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <cerrno> 17#include <cstdio> 18#include <cstdlib> 19#include <string> 20#include <fcntl.h> 21#include <unistd.h> 22#include <vector> 23#include <arpa/inet.h> 24#include <gtest/gtest.h> 25#include <netinet/in.h> 26#include <sys/stat.h> 27#include <sys/socket.h> 28#include <sys/types.h> 29#include "securec.h" 30 31using namespace testing::ext; 32 33static const int TEST_PRIORITY = 1; 34 35class HatsSchedparamTest : public testing::Test { 36public: 37static void SetUpTestCase(); 38static void TearDownTestCase(); 39void SetUp(); 40void TearDown(); 41private: 42}; 43void HatsSchedparamTest::SetUp() 44{ 45} 46void HatsSchedparamTest::TearDown() 47{ 48} 49void HatsSchedparamTest::SetUpTestCase() 50{ 51} 52void HatsSchedparamTest::TearDownTestCase() 53{ 54} 55 56/* 57 * @tc.number : SUB_KERNEL_SYSCALL_SCHEDPARAM_0100 58 * @tc.name : SchedparamSetAndGetParametersSuccess_0001 59 * @tc.desc : sched_setparam set param and sched_setparam get priority param success. 60 * @tc.size : MediumTest 61 * @tc.type : Function 62 * @tc.level : Level 1 63 */ 64HWTEST_F(HatsSchedparamTest, SchedparamSetAndGetParametersSuccess_0001, Function | MediumTest | Level1) 65{ 66 struct sched_param param = { 67 .sched_priority = TEST_PRIORITY, 68 }; 69 70 int ret = sched_setscheduler(0, SCHED_FIFO, ¶m); 71 EXPECT_EQ(ret, 0); 72 73 // test sched_setparam set priority success 74 param.sched_priority = SCHED_FIFO; 75 ret = sched_setparam(0, ¶m); 76 EXPECT_EQ(ret, 0); 77 78 memset_s(¶m, sizeof(struct sched_param), 0, sizeof(struct sched_param)); 79 80 // test sched_getparam get priority success 81 ret = sched_getparam(0, ¶m); 82 EXPECT_EQ(ret, 0); 83 EXPECT_EQ(param.sched_priority, SCHED_FIFO); 84} 85 86/* 87 * @tc.number : SUB_KERNEL_SYSCALL_SCHEDPARAM_0200 88 * @tc.name : SchedparamUseInvalidParmFailed_00002 89 * @tc.desc : sched_setparam and sched_getparam use invalid param failed. 90 * @tc.size : MediumTest 91 * @tc.type : Function 92 * @tc.level : Level 2 93 */ 94HWTEST_F(HatsSchedparamTest, SchedparamUseInvalidParmFailed_00002, Function | MediumTest | Level2) 95{ 96 struct sched_param param = { 97 .sched_priority = TEST_PRIORITY, 98 }; 99 100 // test sched_setparam use pid = -1 failed, errno EINVAL 101 errno = 0; 102 int ret = sched_getparam(-1, ¶m); 103 EXPECT_EQ(ret, -1); 104 EXPECT_EQ(errno, EINVAL); 105 106 // test sched_getparam use pid = -1 pid failed, errno EINVAL 107 errno = 0; 108 ret = sched_getparam(-1, ¶m); 109 EXPECT_EQ(ret, -1); 110 EXPECT_EQ(errno, EINVAL); 111 112 // test sched_setparam use param nullptr failed, errno EINVAL 113 errno = 0; 114 ret = sched_setparam(0, nullptr); 115 EXPECT_EQ(ret, -1); 116 EXPECT_EQ(errno, EINVAL); 117 118 // test sched_getparam use param nullptr failed, errno EINVAL 119 errno = 0; 120 ret = sched_getparam(0, nullptr); 121 EXPECT_EQ(ret, -1); 122 EXPECT_EQ(errno, EINVAL); 123} 124