selftests: futex: Add Futex Wait Multiple wake up test

Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
parent 55730d6a
......@@ -14,7 +14,8 @@ TEST_GEN_FILES := \
futex_requeue_pi_signal_restart \
futex_requeue_pi_mismatched_ops \
futex_wait_uninitialized_heap \
futex_wait_private_mapped_file
futex_wait_private_mapped_file \
futex_wait_multiple
TEST_PROGS := run.sh
......
// SPDX-License-Identifier: GPL-2.0-or-later
/******************************************************************************
*
* Copyright © Collabora, Ltd.
*
* DESCRIPTION
* Test basic semantics of FUTEX_WAIT_MULTIPLE
*
* AUTHOR
* Gabriel Krisman Bertazi <krisman@collabora.com>
*
*****************************************************************************/
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include "futextest.h"
#include "logging.h"
#define TEST_NAME "futex-wait-multiple"
#define timeout_ns 100000
#define MAX_COUNT 128
#define WAKE_WAIT_US 3000000
char *progname;
futex_t f[MAX_COUNT];
struct futex_wait_block fwb[MAX_COUNT];
void usage(char *prog)
{
printf("Usage: %s\n", prog);
printf(" -c Use color\n");
printf(" -h Display this help message\n");
printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
VQUIET, VCRITICAL, VINFO);
}
void test_count_overflow()
{
futex_t f = FUTEX_INITIALIZER;
struct futex_wait_block fwb[MAX_COUNT+1];
int ret, i;
ksft_print_msg("%s: Test a too big number of futexes\n",
progname);
for (i = 0; i < MAX_COUNT+1; i++) {
fwb[i].uaddr = &f;
fwb[i].val = f;
fwb[i].bitset = 0;
}
ret = futex_wait_multiple(fwb, MAX_COUNT+1, NULL,
FUTEX_PRIVATE_FLAG);
if (ret != -1 || errno != EINVAL) {
ksft_test_result_fail("futex_wait_multiple returned %d %d\n",
ret < 0? errno:ret);
}
ksft_test_result_pass("futex_wait_multiple count overflow succeed\n");
}
void *waiterfn(void *arg)
{
int ret;
ret = futex_wait_multiple(fwb, MAX_COUNT, NULL, FUTEX_PRIVATE_FLAG);
if (ret < 0)
ksft_print_msg("waiter failed %d\n", ret);
info("futex_wait: Got hint futex %d was freed\n", ret);
return NULL;
}
void test_fwb_wakeup()
{
int ret, i;
pthread_t waiter;
ksft_print_msg("%s: Test wake up in a list of futex\n", progname);
for (i = 0; i < MAX_COUNT; i++) {
f[i] = 0;
fwb[i].uaddr = &f[i];
fwb[i].val = f[i];
fwb[i].bitset = 0xffffffff;
}
ret = pthread_create(&waiter, NULL, waiterfn, NULL);
if (ret) {
ksft_test_result_fail("Creating waiting thread failed");
ksft_exit_fail();
}
usleep(WAKE_WAIT_US);
ret = futex_wake(&(f[MAX_COUNT-1]), 1, FUTEX_PRIVATE_FLAG);
if (ret != 1) {
ksft_test_result_fail("Failed to wake the thread ret=%d\n", ret);
ksft_exit_fail();
}
pthread_join(waiter, NULL);
ksft_test_result_pass("test_fwb_wakeup succeed\n");
}
int main(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "cht:v:")) != -1) {
switch (c) {
case 'c':
log_color(1);
break;
case 'h':
usage(basename(argv[0]));
exit(0);
case 'v':
log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
exit(1);
}
}
progname = basename(argv[0]);
ksft_print_header();
ksft_set_plan(2);
test_count_overflow();
test_fwb_wakeup();
ksft_print_cnts();
return 0;
}
......@@ -73,3 +73,6 @@ echo
echo
./futex_wait_uninitialized_heap $COLOR
./futex_wait_private_mapped_file $COLOR
echo
./futex_wait_multiple $COLOR
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment