• 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 
9 /*\
10  * [Description]
11  *
12  * Basic test for the socketcall(2) raw syscall.
13  *
14  * Test creating TCP, UDP, raw socket and unix domain dgram.
15  */
16 
17 #include <unistd.h>
18 #include <errno.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <linux/net.h>
22 #include <sys/un.h>
23 #include <netinet/in.h>
24 
25 #include "tst_test.h"
26 #include "lapi/syscalls.h"
27 
28 struct test_case_t {
29 	int call;
30 	unsigned long args[3];
31 	char *desc;
32 } TC[] = {
33 	{SYS_SOCKET, {PF_INET, SOCK_STREAM, 0}, "TCP stream"},
34 	{SYS_SOCKET, {PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"},
35 	{SYS_SOCKET, {AF_INET, SOCK_RAW, 6}, "Raw socket"},
36 	{SYS_SOCKET, {PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
37 };
38 
verify_socketcall(unsigned int i)39 void verify_socketcall(unsigned int i)
40 {
41 	TEST(tst_syscall(__NR_socketcall, TC[i].call, TC[i].args));
42 
43 	if (TST_RET < 0) {
44 		tst_res(TFAIL | TTERRNO, "socketcall() for %s failed with %li",
45 			TC[i].desc, TST_RET);
46 		return;
47 	}
48 
49 	tst_res(TPASS, "socketcall() for %s", TC[i].desc);
50 
51 	SAFE_CLOSE(TST_RET);
52 }
53 
54 static struct tst_test test = {
55 	.test = verify_socketcall,
56 	.tcnt = ARRAY_SIZE(TC),
57 	.needs_root = 1,
58 };
59