1#!/bin/sh 2 3# 4# Copyright (c) 2016 EMC Corp. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28 29# Time creating and deleting a number of files once a minute. 30 31. ../default.cfg 32[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 33 34export LANG=C 35dir=/tmp 36runtime=1200 # default 37[ $# -eq 1 ] && runtime=$1 38odir=`pwd` 39cd $dir 40sed '1,/^EOF/d' < $odir/$0 > $dir/burnin.c 41mycc -o burnin -Wall -Wextra -O0 -g burnin.c || exit 1 42rm -f burnin.c 43cd $odir 44 45mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint 46mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 47mdconfig -a -t swap -s 1g -u $mdstart || exit 1 48bsdlabel -w md$mdstart auto 49newfs -n md${mdstart}$part > /dev/null 50mount /dev/md${mdstart}$part $mntpoint 51d=`date '+%Y%m%dT%H%M%S'` 52log=/tmp/burnin.$d.log 53mode=`pgrep -q cron && echo "Multi-user" || echo "Single-user"` 54echo "# `uname -a` $mode mode `hostname`" > $log 55 56/tmp/burnin -r 10 -d $mntpoint > /dev/null 2>&1 57/tmp/burnin -r $runtime -d $mntpoint >> $log 58 59ministat -A -C 2 -w 72 $log | tail -1 | awk '{if ($NF > .1) exit(1)}' 60s=$? 61[ $s -ne 0 ] && ministat -C 2 -w 72 $log 62 63while mount | grep "on $mntpoint " | grep -q /dev/md; do 64 umount $mntpoint || sleep 1 65done 66mdconfig -d -u $mdstart 67rm -rf /tmp/burnin $log 68exit 0 69EOF 70#include <sys/param.h> 71#include <sys/mman.h> 72#include <sys/stat.h> 73#include <sys/wait.h> 74 75#include <machine/atomic.h> 76 77#include <err.h> 78#include <errno.h> 79#include <fcntl.h> 80#include <stdio.h> 81#include <stdlib.h> 82#include <time.h> 83#include <unistd.h> 84 85#define DELAY 60 86#define SYNC 0 87 88volatile u_int *share; 89int bufsize, files, parallel, runtime; 90char *buf, *dir; 91 92void 93usage(void) 94{ 95 fprintf(stderr, "Usage: %s [-b buf size] [-d directory] [-p parallel] " 96 "[-r runtime]\n", 97 getprogname()); 98 _exit(1); 99} 100 101void 102test(void) 103{ 104 pid_t pid; 105 int fd, i; 106 char path[MAXPATHLEN + 1]; 107 108 atomic_add_int(&share[SYNC], 1); 109 while (share[SYNC] != (volatile u_int)parallel) 110 ; 111 112 pid =getpid(); 113 for (i = 0; i < files; i++) { 114 snprintf(path, sizeof(path), "%s/f%06d.%06d", dir, pid, i); 115 if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) == 116 -1) 117 err(1, "open(%s)", path); 118 if (write(fd, buf, bufsize) != bufsize) 119 err(1, "write()"); 120 if (close(fd) == -1) 121 err(1, "close(%d)", fd); 122 if (unlink(path) == -1) 123 err(1, "unlink(%s)", path); 124 } 125 126 _exit(0); 127} 128 129int 130main(int argc, char *argv[]) 131{ 132 struct timeval t1, t2, diff; 133 struct tm *tp; 134 size_t len; 135 time_t start, now; 136 int ch, e, i, *pids, status; 137 char help[80]; 138 139 bufsize = 8 * 1024; 140 dir = "/tmp"; 141 files = 5000; 142 parallel = 4; 143 runtime = 1 * 60 * 60 * 24; 144 145 while ((ch = getopt(argc, argv, "b:d:f:r:")) != -1) 146 switch(ch) { 147 case 'b': /* bufsize */ 148 if (sscanf(optarg, "%d", &bufsize) != 1) 149 usage(); 150 break; 151 case 'd': /* dir */ 152 dir = optarg; 153 break; 154 case 'f': /* files */ 155 if (sscanf(optarg, "%d", &files) != 1) 156 usage(); 157 break; 158 case 'p': /* parallel */ 159 if (sscanf(optarg, "%d", ¶llel) != 1) 160 usage(); 161 break; 162 case 'r': /* runtime */ 163 if (sscanf(optarg, "%d", &runtime) != 1) 164 usage(); 165 break; 166 default: 167 usage(); 168 } 169 argc -= optind; 170 argv += optind; 171 172 printf("# Options used: dir=%s, bufsize=%d, files=%d, parallel=%d, " 173 "runtime=%d\n", 174 dir, bufsize, files, parallel, runtime); 175 if ((buf = malloc(bufsize)) == NULL) 176 err(1, "malloc(%d)", bufsize); 177 if ((pids = malloc(sizeof(pid_t) * parallel)) == NULL) 178 err(1, "malloc(%d)", (int)(sizeof(pid_t) * parallel)); 179 e = 0; 180 len = PAGE_SIZE; 181 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, 182 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) 183 err(1, "mmap"); 184 185 start = time(NULL); 186 while ((time(NULL) - start) < runtime && e == 0) { 187 share[SYNC] = 0; 188 gettimeofday(&t1, NULL); 189 for (i = 0; i < parallel; i++) { 190 if ((pids[i] = fork()) == 0) 191 test(); 192 } 193 for (i = 0; i < parallel; i++) { 194 waitpid(pids[i], &status, 0); 195 e += status == 0 ? 0 : 1; 196 } 197 gettimeofday(&t2, NULL); 198 timersub(&t2, &t1, &diff); 199 now = time(NULL); 200 tp = localtime(&now); 201 strftime(help, sizeof(help), "%Y%m%d%H%M%S", tp); 202 printf("%s %ld.%06ld\n", help, (long)diff.tv_sec, 203 diff.tv_usec); 204 fflush(stdout); 205 if (runtime > DELAY) 206 sleep(DELAY); 207 } 208 209 return (e); 210} 211