Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
Signed-off-by: Shaan Nobee <sniper111@gmail.com>
  • Loading branch information
shaan1337 committed Nov 30, 2021
1 parent 9e71a60 commit 8466b2d
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/no_space/Makefile
tests/zfs-tests/tests/functional/nopwrite/Makefile
tests/zfs-tests/tests/functional/online_offline/Makefile
tests/zfs-tests/tests/functional/page_writeback/Makefile
tests/zfs-tests/tests/functional/pam/Makefile
tests/zfs-tests/tests/functional/pool_checkpoint/Makefile
tests/zfs-tests/tests/functional/pool_names/Makefile
Expand Down
4 changes: 4 additions & 0 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ tags = ['functional', 'mmp']
tests = ['umount_unlinked_drain']
tags = ['functional', 'mount']

[tests/functional/page_writeback:Linux]
tests = ['run_msync_test']
tags = ['functional', 'page_writeback']

[tests/functional/pam:Linux]
tests = ['pam_basic', 'pam_nounmount']
tags = ['functional', 'pam']
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ SUBDIRS = \

if BUILD_LINUX
SUBDIRS += \
page_writeback \
tmpfile
endif
2 changes: 2 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msync_test
msync_file
14 changes: 14 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include $(top_srcdir)/config/Rules.am

pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/page_writeback

dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
run_msync_test.ksh

pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/page_writeback

pkgexec_PROGRAMS = msync_test
msync_test_SOURCES = msync_test.c

50 changes: 50 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

# Revert the settings to some sensible defaults if something went wrong
# and we were not able to revert back to the original values. (e.g if the
# test had failed or the previous test run was interrupted)

if [ $(cat /proc/sys/vm/dirty_expire_centisecs) -eq 1 ]; then
sudo /bin/sh -c "echo 3000 > /proc/sys/vm/dirty_expire_centisecs"
fi

if [ $(cat /proc/sys/vm/dirty_background_ratio) -eq 0 ]; then
sudo /bin/sh -c "echo 10 > /proc/sys/vm/dirty_background_ratio"
fi

if [ $(cat /proc/sys/vm/dirty_writeback_centisecs) -eq 1 ]; then
sudo /bin/sh -c "echo 500 > /proc/sys/vm/dirty_writeback_centisecs"
fi

default_cleanup
128 changes: 128 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/msync_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>

#define RUN_TIME_MINS 2

void cleanup(char *file);

void
cleanup(char *file)
{
remove(file);
}

int
main(int argc, char *argv[])
{
char *testdir = getenv("TESTDIR");
if (!testdir)
{
fprintf(stderr, "environment variable TESTDIR not set\n");
exit(1);
}

char filepath[512];
filepath[0] = '\0';
char *file = &filepath[0];

strcat(file, testdir);
strcat(file,"/msync_file");

const int LEN = 8;
cleanup(file);

int fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

if (ftruncate(fd, LEN) != 0)
{
fprintf(stderr, "ftruncate failed\n");
cleanup(file);
return 1;
}

void *ptr = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (ptr == MAP_FAILED)
{
fprintf(stderr, "mmap failed!\n");
cleanup(file);
return 1;
}

struct timeval tstart;
gettimeofday(&tstart, NULL);

long long x = 0LL;

for (;;)
{
*((long long*)ptr) = x;
x++;

struct timeval t1, t2;
gettimeofday(&t1, NULL);
if (msync(ptr, LEN, MS_SYNC|MS_INVALIDATE) != 0)
{
fprintf(stderr, "msync failed!\n");
cleanup(file);
return 1;
}

gettimeofday(&t2, NULL);

double elapsed = (t2.tv_sec - t1.tv_sec) * 1000.0;
elapsed += ((t2.tv_usec - t1.tv_usec) / 1000.0);
if (elapsed > 1000.0)
{
fprintf(stderr, "slow msync: %f ms\n", elapsed);
munmap(ptr, LEN);
cleanup(file);
return 1;
}

double elapsed_start = (t2.tv_sec - tstart.tv_sec) * 1000.0;
elapsed_start += ((t2.tv_usec - tstart.tv_usec) / 1000.0);
if (elapsed_start > (RUN_TIME_MINS) * 60 * 1000)
{
break;
}
}

int ret = munmap(ptr, LEN);
if (ret == -1)
{
fprintf(stderr, "munmap failed!\n");
cleanup(file);
return 1;
}

cleanup(file);
return 0;
}
43 changes: 43 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/run_msync_test.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/ksh -p

#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# Description:
# Run the tests for msync.
#

if is_linux; then
log_assert "Run the tests for msync"

saved_vm_dirty_expire_centisecs=$(cat /proc/sys/vm/dirty_expire_centisecs)
saved_vm_dirty_background_ratio=$(cat /proc/sys/vm/dirty_background_ratio)
saved_vm_dirty_writeback_centisecs=$(cat /proc/sys/vm/dirty_writeback_centisecs)

log_must sudo /bin/sh -c "echo 1 > /proc/sys/vm/dirty_expire_centisecs"
log_must sudo /bin/sh -c "echo 1 > /proc/sys/vm/dirty_background_bytes"
log_must sudo /bin/sh -c "echo 1 > /proc/sys/vm/dirty_writeback_centisecs"

log_must $STF_SUITE/tests/functional/page_writeback/msync_test

sudo /bin/sh -c "echo $saved_vm_dirty_expire_centisecs > /proc/sys/vm/dirty_expire_centisecs"
sudo /bin/sh -c "echo $saved_vm_dirty_background_ratio > /proc/sys/vm/dirty_background_ratio"
sudo /bin/sh -c "echo $saved_vm_dirty_writeback_centisecs > /proc/sys/vm/dirty_writeback_centisecs"

log_pass "msync tests passed."
fi
36 changes: 36 additions & 0 deletions tests/zfs-tests/tests/functional/page_writeback/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

DISK=${DISKS%% *}

default_setup ${DISK}

0 comments on commit 8466b2d

Please sign in to comment.