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 <errno.h> 17#include <string.h> 18#include <stdarg.h> 19#include <syslog.h> 20#include "test.h" 21 22#define INVALID_LEVEL (-1) 23 24/** 25 * @tc.name : vsyslog_0100 26 * @tc.desc : generates a log message 27 * @tc.level : Level 0 28 */ 29void vsyslog_0100(char *s, ...) 30{ 31 errno = 0; 32 va_list ap; 33 va_start(ap, s); 34 vsyslog(LOG_INFO, s, ap); 35 if (errno != 0) { 36 t_error("%s failed: errno = %d\n", __func__, errno); 37 } 38 va_end(ap); 39} 40 41/** 42 * @tc.name : vsyslog_0200 43 * @tc.desc : generates a log message with an invalid level 44 * @tc.level : Level 2 45 */ 46void vsyslog_0200(char *s, ...) 47{ 48 errno = 0; 49 va_list ap; 50 va_start(ap, s); 51 vsyslog(INVALID_LEVEL, s, ap); 52 if (errno == 0) { 53 t_error("%s failed: errno = %d\n", __func__, errno); 54 } 55 va_end(ap); 56} 57 58int main(int argc, char *argv[]) 59{ 60 vsyslog_0100("vsyslog: %d", 1); 61 vsyslog_0200("vsyslog: %d", 1); 62 return t_status; 63} 64