• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5  * Copyright (c) Linux Test Project, 2017-2020
6  * Author: Sowmya Adiga <sowmya.adiga@wipro.com>
7  *
8  * This is a basic test for the socketcall(2) system call.
9  */
10 
11 #include <unistd.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <linux/net.h>
16 #include <sys/un.h>
17 #include <netinet/in.h>
18 
19 #include "tst_test.h"
20 #include "lapi/syscalls.h"
21 
22 struct test_case_t {
23 	int call;
24 	unsigned long args[3];
25 	char *desc;
26 } TC[] = {
27 	{SYS_SOCKET, {PF_INET, SOCK_STREAM, 0}, "TCP stream"},
28 	{SYS_SOCKET, {PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"},
29 	{SYS_SOCKET, {AF_INET, SOCK_RAW, 6}, "Raw socket"},
30 	{SYS_SOCKET, {PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
31 };
32 
verify_socketcall(unsigned int i)33 void verify_socketcall(unsigned int i)
34 {
35 	TEST(tst_syscall(__NR_socketcall, TC[i].call, TC[i].args));
36 
37 	if (TST_RET < 0) {
38 		tst_res(TFAIL | TTERRNO, "socketcall() for %s failed with %li",
39 			TC[i].desc, TST_RET);
40 		return;
41 	}
42 
43 	tst_res(TPASS, "socketcall() for %s", TC[i].desc);
44 
45 	SAFE_CLOSE(TST_RET);
46 }
47 
48 static struct tst_test test = {
49 	.test = verify_socketcall,
50 	.tcnt = ARRAY_SIZE(TC),
51 	.needs_root = 1,
52 };
53