summaryrefslogtreecommitdiffstats
path: root/tests/test_close_failure.c
blob: 8a6d40ef165a5e07e392671f22154f390ad7fab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "torture.h"

#include <errno.h>
#include <stdio.h>
#include <cmocka.h>
#include <unistd.h>
#include <stdlib.h>

static int setup(void **state)
{
	torture_setup_socket_dir(state);

	return 0;
}

static int teardown(void **state)
{
	torture_teardown_socket_dir(state);

	return 0;
}

static void test_close_failure(void **state)
{
	int s;

	(void) state; /* unused */

	s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	assert_int_not_equal(s, -1);

	/* Do not close the socket here so that destructor
	 * handles it and no hang should be observed.*/
}

int main(void) {
	int rc;

	const struct CMUnitTest close_failure_tests[] = {
		cmocka_unit_test_setup_teardown(test_close_failure,
						setup, teardown),
	};

	rc = cmocka_run_group_tests(close_failure_tests, NULL, NULL);

	return rc;
}