From patchwork Thu May 27 16:03:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 448860 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp642296jac; Thu, 27 May 2021 09:07:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhhDnye2u5iTxbpaOc1Q0Yym0bG30Mk1mCsO1zUfOUXHMnGlrDaMzwwTLUOrdgeYSMhe8G X-Received: by 2002:a05:6402:2788:: with SMTP id b8mr4828555ede.335.1622131669829; Thu, 27 May 2021 09:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622131669; cv=none; d=google.com; s=arc-20160816; b=HOu6hzBU81GwamtwtuYaWP2cVcBnskNZ3xAnEk7+Uc2V0Ao2SXZ3mf0rpmZT1kg8oO x4EvZpN7URQ8aT1Qx5bO9szsSqDvddYNk7zp/sFUEVB1M+Gr7I9MXfc8Y3nrVyZt3IPi lWFB8PzZNYTzOGJsFphqYId3PkUr/Gzhpe4fBCgQ8N8uvQXcyX2Nf8YikpoSqqxjLmRu dnkkACkDeRFf+AUpmeg3lnauLWWBUSsEHamDVHy+CcS9zzs+7wczMMog0uQi6VPZAwjD bfR2ql559VVuhsGR5WFnKn9rAWbqLEQZ3Ew8B/yVOQT1lxzMKKa2swQTs6X60BaMuiEW GjKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mz6OklwamQYvc3w9qT/mb2Gq27rR9WEvelWLrLCdxIU=; b=imFqFFzLtqGwHns2WEydTDJG0rlp4ObYtnmKwXqiOYZ2dXl5SsqICVGts63veQTONb ENaMBK5tRwAyWC1ij74r8xvE++nCSufei6HK7HroT+CNN7SFp4VhtVj6SNU8klp1ziqN BD+Ku8HAcW3O+Ns3dZMiDHduyOD64SrDUKK+fTXEIMN3jnrxbgCn/q8okq4J24JTHP// qhlXAHNoku7o6DppRoHVlbhbAeUqSJqZkrYmG/5+WJpo/D0PGUs9g/t37jj7lQ0II7qS sk15f9xDWnHOhy2SsMVF0rL8bi8lsLbVcxBsrE9Ui1hqNM3HljMh6jy/i9FyMelgsDuL 7tbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DDyr73q5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id hs26si2376891ejc.307.2021.05.27.09.07.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 May 2021 09:07:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DDyr73q5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmIY0-00016r-Mi for patch@linaro.org; Thu, 27 May 2021 12:07:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmITm-0004oS-4p for qemu-devel@nongnu.org; Thu, 27 May 2021 12:03:26 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:34592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lmITj-0000K7-59 for qemu-devel@nongnu.org; Thu, 27 May 2021 12:03:25 -0400 Received: by mail-wr1-x42f.google.com with SMTP id f11so447780wrq.1 for ; Thu, 27 May 2021 09:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mz6OklwamQYvc3w9qT/mb2Gq27rR9WEvelWLrLCdxIU=; b=DDyr73q5RF9tSkYzgnJ1Vsu6kGSMgMDCJ1aCx4v/NuqUBSpRmKnWZtXODuAikntoOU a/RgEobt2PVJmhwWx4hk6fyzpfT+jO3QWbUB0KUfDXmMYx7jRfR690LnvociD37ZJ/KC V90PidXJZZRvqepL535ndpwaYFMiqBYgccUuT8WW5ZzZloDGXHH+RDZIDSF1Wo9wm11p 97eWE9u+9hYFR85Cbs4kZgXmPID7TaQQ1y6H/dlVDKHQlrPQYSiNTwrxYwgQk9Vj6ClS rL++Z36XVuO7qZ52rtafvVMRPR1Cd3VvaqNji8lMT813/huh219LSU+uL6QnSWUbaIuA U/EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mz6OklwamQYvc3w9qT/mb2Gq27rR9WEvelWLrLCdxIU=; b=niRsG2blB8+2ousZ9oJX1uEUS79glaRSxdMi+ffUaOGH2WDwi5ujGAvpUv/wZW2m+a nrFBRI+VWoOyC6+GC3Ffi4ZUMIJIBRd5C4J2VG4PdtzZrxLDmC+KY1E7zw5lML+qusMm prtNRGi6FCSlpxH14Jb1qSDqMY3RyQ9JVahU+CU24Etog1KebXnaIHYcpV1IsLno0kBN vDJSKCcnlrEa1qjWZRh23zD/Tp/9tXLyGa0JwlZXGGXqpGDABQilWE2uLTsHSIj0Odq9 mnB8uS5itgqjVl0VWvfr5q4GvBZ1NzNiKJ2v4qqza7RodgHRbWd3RPMIVK1hpaHBMU+Q lOOA== X-Gm-Message-State: AOAM5309C+K9xs2qCoWMgWbeDUHDJVj4rz4TIR21vRxrwA/aA6gwGlnN qyNHkByCXLWDKzlRfrY38qEwAQ== X-Received: by 2002:a5d:4151:: with SMTP id c17mr4224079wrq.262.1622131401270; Thu, 27 May 2021 09:03:21 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s11sm11354478wmf.14.2021.05.27.09.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 09:03:20 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7B4251FF87; Thu, 27 May 2021 17:03:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/6] tests/tcg: add a multiarch signals test to stress test signal delivery Date: Thu, 27 May 2021 17:03:14 +0100 Message-Id: <20210527160319.19834-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210527160319.19834-1-alex.bennee@linaro.org> References: <20210527160319.19834-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This adds a simple signal test that combines the POSIX timer_create with signal delivery across multiple threads. The aim is to provide a bit more of a stress test to flush out signal handling issues for easily than the occasional random crash we sometimes see in linux-test or threadcount. [AJB: this is still triggering intermittent failures in some guests so will probably be kept out of PRs until that is fixed.] Signed-off-by: Alex Bennée Message-Id: <20210504100223.25427-29-alex.bennee@linaro.org> --- tests/tcg/multiarch/signals.c | 149 ++++++++++++++++++++++++++++ tests/tcg/multiarch/Makefile.target | 2 + 2 files changed, 151 insertions(+) create mode 100644 tests/tcg/multiarch/signals.c -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/tests/tcg/multiarch/signals.c b/tests/tcg/multiarch/signals.c new file mode 100644 index 0000000000..998c8fdefd --- /dev/null +++ b/tests/tcg/multiarch/signals.c @@ -0,0 +1,149 @@ +/* + * linux-user signal handling tests. + * + * Copyright (c) 2021 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void error1(const char *filename, int line, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(stderr, "%s:%d: ", filename, line); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); + exit(1); +} + +static int __chk_error(const char *filename, int line, int ret) +{ + if (ret < 0) { + error1(filename, line, "%m (ret=%d, errno=%d/%s)", + ret, errno, strerror(errno)); + } + return ret; +} + +#define error(fmt, ...) error1(__FILE__, __LINE__, fmt, ## __VA_ARGS__) + +#define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret)) + +/* + * Thread handling + */ +typedef struct ThreadJob ThreadJob; + +struct ThreadJob { + int number; + int sleep; + int count; +}; + +static pthread_t *threads; +static int max_threads = 10; +__thread int signal_count; +int total_signal_count; + +static void *background_thread_func(void *arg) +{ + ThreadJob *job = (ThreadJob *) arg; + + printf("thread%d: started\n", job->number); + while (total_signal_count < job->count) { + usleep(job->sleep); + } + printf("thread%d: saw %d alarms from %d\n", job->number, + signal_count, total_signal_count); + return NULL; +} + +static void spawn_threads(void) +{ + int i; + threads = calloc(sizeof(pthread_t), max_threads); + + for (i = 0; i < max_threads; i++) { + ThreadJob *job = calloc(sizeof(ThreadJob), 1); + job->number = i; + job->sleep = i * 1000; + job->count = i * 100; + pthread_create(threads + i, NULL, background_thread_func, job); + } +} + +static void close_threads(void) +{ + int i; + for (i = 0; i < max_threads; i++) { + pthread_join(threads[i], NULL); + } + free(threads); + threads = NULL; +} + +static void sig_alarm(int sig, siginfo_t *info, void *puc) +{ + if (sig != SIGRTMIN) { + error("unexpected signal"); + } + signal_count++; + __atomic_fetch_add(&total_signal_count, 1, __ATOMIC_SEQ_CST); +} + +static void test_signals(void) +{ + struct sigaction act; + struct itimerspec it; + timer_t tid; + struct sigevent sev; + + /* Set up SIG handler */ + act.sa_sigaction = sig_alarm; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + chk_error(sigaction(SIGRTMIN, &act, NULL)); + + /* Create POSIX timer */ + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGRTMIN; + sev.sigev_value.sival_ptr = &tid; + chk_error(timer_create(CLOCK_REALTIME, &sev, &tid)); + + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = 1000000; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000000; + chk_error(timer_settime(tid, 0, &it, NULL)); + + spawn_threads(); + + do { + usleep(1000); + } while (total_signal_count < 2000); + + printf("shutting down after: %d signals\n", total_signal_count); + + close_threads(); + + chk_error(timer_delete(tid)); +} + +int main(int argc, char **argv) +{ + test_signals(); + return 0; +} diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index a3a751723d..3f283eabe6 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -30,6 +30,8 @@ testthread: LDFLAGS+=-lpthread threadcount: LDFLAGS+=-lpthread +signals: LDFLAGS+=-lrt -lpthread + # We define the runner for test-mmap after the individual # architectures have defined their supported pages sizes. If no # additional page sizes are defined we only run the default test.