#include <errno.h>
#include <getopt.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "futextest.h"
#include "kselftest_harness.h"
futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER;
int child_ret = 0;
void *blocking_child(void *arg)
{
child_ret = futex_wait(&f1, f1, NULL, FUTEX_PRIVATE_FLAG);
if (child_ret < 0) {
child_ret = -errno;
ksft_exit_fail_msg("futex_wait\n");
}
return (void *)&child_ret;
}
TEST(requeue_pi_mismatched_ops)
{
pthread_t child;
int ret;
if (pthread_create(&child, NULL, blocking_child, NULL))
ksft_exit_fail_msg("pthread_create\n");
sleep(1);
ret = futex_cmp_requeue_pi(&f1, f1, &f2, 1, 0, FUTEX_PRIVATE_FLAG);
if (ret < 0) {
if (errno == EINVAL) {
ret = futex_wake(&f1, 1, FUTEX_PRIVATE_FLAG);
if (ret == 1)
ret = 0;
else if (ret < 0)
ksft_exit_fail_msg("futex_wake\n");
else
ksft_exit_fail_msg("futex_wake did not wake the child\n");
} else {
ksft_exit_fail_msg("futex_cmp_requeue_pi\n");
}
} else if (ret > 0) {
ksft_test_result_fail("futex_cmp_requeue_pi failed to detect the mismatch\n");
} else {
ksft_exit_fail_msg("futex_cmp_requeue_pi found no waiters\n");
}
pthread_join(child, NULL);
if (!ret && !child_ret)
ksft_test_result_pass("futex_requeue_pi_mismatched_ops passed\n");
else
ksft_test_result_pass("futex_requeue_pi_mismatched_ops failed\n");
}
TEST_HARNESS_MAIN