1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 <signal.h> 17 18#include "test.h" 19 20/** 21 * @tc.name : sigwait_0100 22 * @tc.desc : wait for a signal 23 * @tc.level : Level 0 24 */ 25void sigwait_0100(void) 26{ 27 sigset_t set = {0}; 28 int result = sigemptyset(&set); 29 if (result != 0) { 30 t_error("%s failed: result = %d\n", __func__, result); 31 } 32 33 int sig = SIGALRM; 34 result = sigaddset(&set, sig); 35 if (result != 0) { 36 t_error("%s failed: result = %d\n", __func__, result); 37 } 38 39 result = sigprocmask(SIG_BLOCK, &set, NULL); 40 if (result != 0) { 41 t_error("%s failed: result = %d\n", __func__, result); 42 } 43 44 union sigval sigval = {.sival_int = 1}; 45 result = sigqueue(getpid(), sig, sigval); 46 if (result != 0) { 47 t_error("%s failed: result = %d\n", __func__, result); 48 } 49 50 sig = 0; 51 result = sigwait(&set, &sig); 52 if (result != 0) { 53 t_error("%s failed: result = %d\n", __func__, result); 54 } 55 56 if (sig != SIGALRM) { 57 t_error("%s failed: sig = %d\n", __func__, sig); 58 } 59} 60 61int main(int argc, char *argv[]) 62{ 63 sigwait_0100(); 64 65 return t_status; 66} 67