Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/******************************************************************************
  3 *
  4 *   Copyright © International Business Machines  Corp., 2009
  5 *
  6 * DESCRIPTION
  7 *      Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs
  8 *      from the expected one.
  9 *
 10 * AUTHOR
 11 *      Gowrishankar <gowrishankar.m@in.ibm.com>
 12 *
 13 * HISTORY
 14 *      2009-Nov-14: Initial version by Gowrishankar <gowrishankar.m@in.ibm.com>
 15 *
 16 *****************************************************************************/
 17
 18#include <errno.h>
 19#include <getopt.h>
 20#include <stdio.h>
 21#include <stdlib.h>
 22#include <string.h>
 23#include <time.h>
 24#include "futextest.h"
 25#include "futex2test.h"
 26#include "logging.h"
 27
 28#define TEST_NAME "futex-wait-wouldblock"
 29#define timeout_ns 100000
 30
 31void usage(char *prog)
 32{
 33	printf("Usage: %s\n", prog);
 34	printf("  -c	Use color\n");
 35	printf("  -h	Display this help message\n");
 36	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
 37	       VQUIET, VCRITICAL, VINFO);
 38}
 39
 40int main(int argc, char *argv[])
 41{
 42	struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
 43	futex_t f1 = FUTEX_INITIALIZER;
 44	int res, ret = RET_PASS;
 45	int c;
 46	struct futex_waitv waitv = {
 47			.uaddr = (uintptr_t)&f1,
 48			.val = f1+1,
 49			.flags = FUTEX_32,
 50			.__reserved = 0
 51		};
 52
 53	while ((c = getopt(argc, argv, "cht:v:")) != -1) {
 54		switch (c) {
 55		case 'c':
 56			log_color(1);
 57			break;
 58		case 'h':
 59			usage(basename(argv[0]));
 60			exit(0);
 61		case 'v':
 62			log_verbosity(atoi(optarg));
 63			break;
 64		default:
 65			usage(basename(argv[0]));
 66			exit(1);
 67		}
 68	}
 69
 70	ksft_print_header();
 71	ksft_set_plan(2);
 72	ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
 73	       basename(argv[0]));
 74
 75	info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
 76	res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
 77	if (!res || errno != EWOULDBLOCK) {
 78		ksft_test_result_fail("futex_wait returned: %d %s\n",
 79				      res ? errno : res,
 80				      res ? strerror(errno) : "");
 81		ret = RET_FAIL;
 82	} else {
 83		ksft_test_result_pass("futex_wait\n");
 84	}
 85
 86	if (clock_gettime(CLOCK_MONOTONIC, &to)) {
 87		error("clock_gettime failed\n", errno);
 88		return errno;
 89	}
 90
 91	to.tv_nsec += timeout_ns;
 92
 93	if (to.tv_nsec >= 1000000000) {
 94		to.tv_sec++;
 95		to.tv_nsec -= 1000000000;
 96	}
 97
 98	info("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
 99	res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC);
100	if (!res || errno != EWOULDBLOCK) {
101		ksft_test_result_pass("futex_waitv returned: %d %s\n",
102				      res ? errno : res,
103				      res ? strerror(errno) : "");
104		ret = RET_FAIL;
105	} else {
106		ksft_test_result_pass("futex_waitv\n");
107	}
108
109	ksft_print_cnts();
110	return ret;
111}
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/******************************************************************************
 3 *
 4 *   Copyright © International Business Machines  Corp., 2009
 5 *
 6 * DESCRIPTION
 7 *      Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs
 8 *      from the expected one.
 9 *
10 * AUTHOR
11 *      Gowrishankar <gowrishankar.m@in.ibm.com>
12 *
13 * HISTORY
14 *      2009-Nov-14: Initial version by Gowrishankar <gowrishankar.m@in.ibm.com>
15 *
16 *****************************************************************************/
17
18#include <errno.h>
19#include <getopt.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <time.h>
24#include "futextest.h"
 
25#include "logging.h"
26
27#define TEST_NAME "futex-wait-wouldblock"
28#define timeout_ns 100000
29
30void usage(char *prog)
31{
32	printf("Usage: %s\n", prog);
33	printf("  -c	Use color\n");
34	printf("  -h	Display this help message\n");
35	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
36	       VQUIET, VCRITICAL, VINFO);
37}
38
39int main(int argc, char *argv[])
40{
41	struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
42	futex_t f1 = FUTEX_INITIALIZER;
43	int res, ret = RET_PASS;
44	int c;
 
 
 
 
 
 
45
46	while ((c = getopt(argc, argv, "cht:v:")) != -1) {
47		switch (c) {
48		case 'c':
49			log_color(1);
50			break;
51		case 'h':
52			usage(basename(argv[0]));
53			exit(0);
54		case 'v':
55			log_verbosity(atoi(optarg));
56			break;
57		default:
58			usage(basename(argv[0]));
59			exit(1);
60		}
61	}
62
63	ksft_print_header();
64	ksft_set_plan(1);
65	ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
66	       basename(argv[0]));
67
68	info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
69	res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
70	if (!res || errno != EWOULDBLOCK) {
71		fail("futex_wait returned: %d %s\n",
72		     res ? errno : res, res ? strerror(errno) : "");
 
73		ret = RET_FAIL;
 
 
74	}
75
76	print_result(TEST_NAME, ret);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77	return ret;
78}