1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2020 Yang Xu <xuyang2018.jy@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci * Author: Sowmya Adiga <sowmya.adiga@wipro.com> 6f08c3bdfSopenharmony_ci * 7f08c3bdfSopenharmony_ci * This is a basic test for the socketcall(2) for bind(2) and listen(2). 8f08c3bdfSopenharmony_ci */ 9f08c3bdfSopenharmony_ci#include <unistd.h> 10f08c3bdfSopenharmony_ci#include <errno.h> 11f08c3bdfSopenharmony_ci#include <sys/types.h> 12f08c3bdfSopenharmony_ci#include <sys/socket.h> 13f08c3bdfSopenharmony_ci#include <linux/net.h> 14f08c3bdfSopenharmony_ci#include <sys/un.h> 15f08c3bdfSopenharmony_ci#include <netinet/in.h> 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic struct sockaddr_in si; 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cistatic void verify_socketcall(void) 23f08c3bdfSopenharmony_ci{ 24f08c3bdfSopenharmony_ci unsigned long args[3]; 25f08c3bdfSopenharmony_ci int s = -1; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci s = SAFE_SOCKET(AF_INET, SOCK_STREAM, 6); 28f08c3bdfSopenharmony_ci args[0] = s; 29f08c3bdfSopenharmony_ci args[1] = (unsigned long)&si; 30f08c3bdfSopenharmony_ci args[2] = sizeof(si); 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_socketcall, SYS_BIND, args)); 33f08c3bdfSopenharmony_ci if (TST_RET < 0) 34f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "socketcall() for bind call failed with %ld", TST_RET); 35f08c3bdfSopenharmony_ci else 36f08c3bdfSopenharmony_ci tst_res(TPASS, "socketcall() for bind call passed, returned %ld", TST_RET); 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci args[1] = 1; 39f08c3bdfSopenharmony_ci args[2] = 0; 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_socketcall, SYS_LISTEN, args)); 42f08c3bdfSopenharmony_ci if (TST_RET < 0) 43f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "socketcall() for listen call failed with %ld", TST_RET); 44f08c3bdfSopenharmony_ci else 45f08c3bdfSopenharmony_ci tst_res(TPASS, "socketcall() for listen call passed, returned %ld", TST_RET); 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci SAFE_CLOSE(s); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic void setup(void) 51f08c3bdfSopenharmony_ci{ 52f08c3bdfSopenharmony_ci si.sin_family = AF_INET; 53f08c3bdfSopenharmony_ci si.sin_addr.s_addr = htons(INADDR_ANY); 54f08c3bdfSopenharmony_ci si.sin_port = 0; 55f08c3bdfSopenharmony_ci} 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_cistatic struct tst_test test = { 58f08c3bdfSopenharmony_ci .setup = setup, 59f08c3bdfSopenharmony_ci .test_all = verify_socketcall, 60f08c3bdfSopenharmony_ci}; 61