From nobody Thu Nov 28 12:17:12 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xzb0S6z9dz5fckX; Thu, 28 Nov 2024 12:17:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xzb0S5ylgz4bdr; Thu, 28 Nov 2024 12:17:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732796232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cZSux6yT/xtYEpmBQUcEpk6IILl3jmGOVkYcVc/e6cs=; b=ifghUItKWuvOo2vDyKBf+1DGMSkF5rpJ6x/PeZeC0lOmjFbv7zfv7LX3Lh916JvGj/lsQj puxVzxOArJbj1ld0en/sMw6+esEB+n0HGrUMza/vXV0kFnRLjhHTdHIbpnzWAxM70qtDfp G862kW0sNMQFZY3jNT8ndP+4FERTveS9XpPRGVjXbkS8bgH16QFhB7f/NKPsc+o8EkuRoI FP2Vz6bRHiO9OAQfDQZ0uRXYfoxLXbtzpBLD6pBhqcmjcNDHch4PkJfBuDpvsJsDr6vl6l phOH86Fx8WJ5NBYHFpZx7j4U8hofsTFfs8faogcxj43EHZDW70D4+nHLeBDlyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732796232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cZSux6yT/xtYEpmBQUcEpk6IILl3jmGOVkYcVc/e6cs=; b=cG/58HUE0W+/j2EPsz/20LLMRGweBBjh6A8zp3G4EDCc8dzpQDQQhn0nkOaPl7Z9/agwbA PqPZB8v9X53fnOudwvADzaE+Znf+M8jQ0nXJdqRy8x+MEe0uB3UwJdV5yb3bsTAywKzMCc IOorjHAcV0y0jz9xfgwZqKExYkRpytXMeghLipig9IVsGSQg1Vj5JSHd+sMjP+RfwNZbsG vgmemJAjfDhpufKa7VUgUaSnhL0dwv05tYyHY6t3yAr+j9U+lTzE/zrimE80mP5+Yex4ys Diz/gKOuqnk7FmMaU8wrHOkBJhHK2dAtezSmWlWKvupgomsznwt/c7hw7rX47w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732796232; a=rsa-sha256; cv=none; b=d1Osz26wijAtj+z1SY+FP0lnlc9qP3cQSHQSrtY3vXx5+E/UERkODMJtgo2LvoE7Slp6GL DDYW/3TKXr4O4R1mVrLA+0lLVxMuRJLElfF/zA6lC5mTOG/8a7zjc/mXZS0rp10xFZSXJh /J+n/Qz5A6DVtrkqW/NFiZmOS44ZHtVrp6FeWWlLewP6VD+dxe5BVpRb3VCsM/OXd7TFrD 6nFSQR6FmdIZJHdzC96Y69U/1K+m3mp5NSH90Yq9H/Zpmxb6BfqC4aLEJs2O+fXhmSiiLv ZxrQ+rHjsjTJ3Va2bUY5YPZhD0h7YKFxLuaZEPYs4aGe25s4bJ3pu0mwdFZjUA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xzb0S5YK9zfP0; Thu, 28 Nov 2024 12:17:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4ASCHCuw074397; Thu, 28 Nov 2024 12:17:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ASCHCS9074394; Thu, 28 Nov 2024 12:17:12 GMT (envelope-from git) Date: Thu, 28 Nov 2024 12:17:12 GMT Message-Id: <202411281217.4ASCHCS9074394@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Peter Holm Subject: git: 2e2699c48a7e - main - stress2: Added new tmpfs test scenarios List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pho X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2e2699c48a7e6b7cbf13611a601a6cd264a80ec5 Auto-Submitted: auto-generated The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=2e2699c48a7e6b7cbf13611a601a6cd264a80ec5 commit 2e2699c48a7e6b7cbf13611a601a6cd264a80ec5 Author: Peter Holm AuthorDate: 2024-11-28 12:16:35 +0000 Commit: Peter Holm CommitDate: 2024-11-28 12:16:35 +0000 stress2: Added new tmpfs test scenarios --- tools/test/stress2/misc/tmpfs26.sh | 179 +++++++++++++++++++++++++++++++++++++ tools/test/stress2/misc/tmpfs27.sh | 49 ++++++++++ tools/test/stress2/misc/tmpfs28.sh | 61 +++++++++++++ 3 files changed, 289 insertions(+) diff --git a/tools/test/stress2/misc/tmpfs26.sh b/tools/test/stress2/misc/tmpfs26.sh new file mode 100755 index 000000000000..25fa59ff37c3 --- /dev/null +++ b/tools/test/stress2/misc/tmpfs26.sh @@ -0,0 +1,179 @@ +#!/bin/sh + +# Bug 272678 - VFS: Incorrect data in read from concurrent write + +# Test scenario by: Kristian Nielsen + +. ../default.cfg + +prog=$(basename "$0" .sh) +cat > /tmp/$prog.c < +#include +#include +#include +#include +#include + +#define MAGIC 0x42 + +const char *filename = "testfile.bin"; + +static FILE *write_file; +static FILE *read_file; +static pthread_mutex_t write_mutex; +static pthread_cond_t write_cond; +static pthread_mutex_t read_mutex; +static pthread_cond_t read_cond; +static pthread_mutex_t state_mutex; +static pthread_cond_t state_cond; +static int write_state; +static int read_state; + +void * +writer_routine(void *arg __unused) +{ + unsigned char data[44]; + + memset(data, MAGIC, sizeof(data)); + pthread_mutex_lock(&write_mutex); + + for (;;) { + + while (write_state != 1) + pthread_cond_wait(&write_cond, &write_mutex); + + fwrite(data, 1, sizeof(data), write_file); + fflush(write_file); + + pthread_mutex_lock(&state_mutex); + write_state = 2; + pthread_cond_signal(&state_cond); + pthread_mutex_unlock(&state_mutex); + } +} + +void * +reader_routine(void *arg __unused) +{ + + for (;;) { + unsigned char buf[387]; + int len; + + while (read_state != 1) + pthread_cond_wait(&read_cond, &read_mutex); + + len = fread(buf, 1, sizeof(buf), read_file); + if (len < (int)sizeof(buf) && ferror(read_file)) { + perror(" read file"); + exit(1); + } + for (int i = 0; i < len; ++i) { + if (buf[i] != MAGIC) { + fprintf(stderr, "ERROR! invalid value read 0x%2x at %d of %d, pos %ld\n", + buf[i], i, len, ftell(read_file)); + exit(126); + } + } + + pthread_mutex_lock(&state_mutex); + read_state = 2; + pthread_cond_signal(&state_cond); + pthread_mutex_unlock(&state_mutex); + } +} + +void +create_threads(void) +{ + pthread_t write_thread_id, read_thread_id; + pthread_attr_t attr; + + pthread_mutex_init(&write_mutex, NULL); + pthread_mutex_init(&read_mutex, NULL); + pthread_mutex_init(&state_mutex, NULL); + pthread_cond_init(&write_cond, NULL); + pthread_cond_init(&read_cond, NULL); + pthread_cond_init(&state_cond, NULL); + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&write_thread_id, &attr, writer_routine, NULL); + pthread_create(&read_thread_id, &attr, reader_routine, NULL); +} + +int +main(int argc, char *argv[]) +{ + int num_iter = 1000; + int i; + unsigned char buf[343]; + + if (argc >= 2) + num_iter = atoi(argv[1]); + + write_state = 0; + read_state = 0; + + create_threads(); + memset(buf, MAGIC, sizeof(buf)); + + for (i = 0; i < num_iter; ++i) { + /* Write the first part of the file. */ + pthread_mutex_lock(&write_mutex); + write_file = fopen(filename, "wb"); + if (!write_file) { + perror(" open file"); + exit(1); + } + fwrite(buf, 1, sizeof(buf), write_file); + fflush(write_file); + + /* Open a read handle on the file. */ + pthread_mutex_lock(&read_mutex); + read_file = fopen(filename, "rb"); + if (!read_file) { + perror(" open read file"); + exit(1); + } + + write_state = 1; + read_state = 1; + pthread_cond_signal(&write_cond); + pthread_mutex_unlock(&write_mutex); + pthread_cond_signal(&read_cond); + pthread_mutex_unlock(&read_mutex); + + pthread_mutex_lock(&state_mutex); + while (write_state != 2 || read_state != 2) + pthread_cond_wait(&state_cond, &state_mutex); + pthread_mutex_unlock(&state_mutex); + + /* Close and remove the file, ready for another iteration. */ + pthread_mutex_lock(&write_mutex); + fclose(write_file); + write_state = 0; + pthread_mutex_unlock(&write_mutex); + + pthread_mutex_lock(&read_mutex); + fclose(read_file); + read_state = 0; + pthread_mutex_unlock(&read_mutex); + + unlink(filename); + } + + return (0); +} +EOF +mycc -o /tmp/$prog -Wall -Wextra -O2 /tmp/$prog.c -lpthread || exit 1 + +mount -t tmpfs dummy $mntpoint +cd $mntpoint +/tmp/$prog; s=$? +cd - +umount $mntpoint + +rm /tmp/$prog /tmp/$prog.c +exit $s diff --git a/tools/test/stress2/misc/tmpfs27.sh b/tools/test/stress2/misc/tmpfs27.sh new file mode 100755 index 000000000000..5479dcd9188a --- /dev/null +++ b/tools/test/stress2/misc/tmpfs27.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# Copyright (c) 2024 Peter Holm +# +# SPDX-License-Identifier: BSD-2-Clause +# + +# umount FS with memory mapped file. tmpfs version. + +# "panic: object with writable mappings does not have a reference" seen: +# https://people.freebsd.org/~pho/stress/log/log0518.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +set -eu +prog=$(basename "$0" .sh) +here=`pwd` +mp1=$mntpoint + +mount -t tmpfs dummy $mp1 + +export RUNDIR=$mp1/stressX +export runRUNTIME=2m +export LOAD=70 +export mmapLOAD=100 +export TESTPROGS="testcases/mmap/mmap testcases/swap/swap" +set +e + +(cd ..; ./testcases/run/run $TESTPROGS > /dev/null 2>&1) & rpid=$! +sleep 5 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 120 ]; do + umount -f $mp1 && + mount -t tmpfs dummy $mp1 + mount | grep -q "on $mp1 " || break + pgrep -q mmap || break +done +pkill run swap mmap +while pgrep -q swap; do pkill swap; done +wait $rpid + +while mount | grep -q "on $mp1 "; do + umount $mp1 +done +exit 0 diff --git a/tools/test/stress2/misc/tmpfs28.sh b/tools/test/stress2/misc/tmpfs28.sh new file mode 100755 index 000000000000..d73e957b7f28 --- /dev/null +++ b/tools/test/stress2/misc/tmpfs28.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2024 Peter Holm +# +# SPDX-License-Identifier: BSD-2-Clause +# + +# A SEEK_HOLE / SEEK_DATA test scenario, variation of tmpfs24.sh + +# A regression test for "40c1672e886b - main - swap_pager: fix +# seek_data with invalid first page" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +prog=$(basename "$0" .sh) +exp=/tmp/$prog.exp +here=`pwd` +log=/tmp/$prog.log + +cc -o /tmp/lsholes -Wall -Wextra -O2 $here/../tools/lsholes.c | exit 1 +cat > $exp < $log 2>&1 || s1=1 + +cmp -s $exp $log || { s2=2; sdiff $exp $log; } + +$here/../testcases/swap/swap -t 2m -i 20 -h > /dev/null & +sleep 10 +cp $file $copy +while pkill swap; do :; done +wait +cmp $file $copy || { echo "copy error"; s3=4; } + +umount $mntpoint +rm -f /tmp/lsholes $exp $log +exit $((s1 + s2 + s3))