summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Ludikovsky <peter@ludikovsky.name>2019-02-11 13:06:53 +0100
committerPeter Ludikovsky <peter@ludikovsky.name>2019-02-11 13:06:53 +0100
commit959a8480975c4af652a18fc914db743ee328c030 (patch)
tree6fc12fa4c6ae8e8830ab652cc98e3ef0b58ff8df
Initial version
-rw-r--r--.gitignore2
-rw-r--r--LICENSE11
-rw-r--r--stress.c125
-rw-r--r--stress.h27
4 files changed, 165 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8164476
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+stress
+.*.swp
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..146ff70
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,11 @@
+Copyright 2019 Peter Ludikovsky
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/stress.c b/stress.c
new file mode 100644
index 0000000..0b7e999
--- /dev/null
+++ b/stress.c
@@ -0,0 +1,125 @@
+#include "stress.h"
+
+void usage(void)
+{
+ printf("Usage: stress [-t n] [-m n]\n");
+ printf("\t-t n\tRun n processes parallel\n");
+ printf("\t-m n\tTest n MiB of Memory\n");
+ printf("\n");
+ printf("\t\tCan be combined\n");
+ exit(0);
+}
+
+void testMemory(unsigned long long size)
+{
+ char *mem=malloc(size*sizeof(char));
+ unsigned long long i;
+ unsigned char run=0;
+
+ while(1==1)
+ {
+ for(i=0; i<size; i++)
+ {
+ mem[i]=(mem[i]+i+run)%256;
+ }
+ run++;
+ }
+}
+
+void testCPU(void)
+{
+ long double f=0;
+ long double res=0;
+ while(1==1)
+ {
+ for(f=0; f<LDBL_MAX; f+=LDBL_EPSILON)
+ {
+ res=sqrtl(f);
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ const char *optargs = "t:m:h";
+ char optc;
+ unsigned long long convtemp;
+
+ unsigned char errflags=0;
+ unsigned char optflags=0;
+
+ unsigned char threads = 1;
+ unsigned long long memory = 1048576LL;
+
+ int i, pid, wstatus;
+
+ while((optc=getopt(argc,argv,optargs))!=-1)
+ {
+ switch(optc)
+ {
+ case 't':
+ if((convtemp = strtoll(optarg, NULL, 10))==0)
+ {
+ errflags|=THREADS;
+ perror("Error with -t: ");
+ }
+ else
+ {
+ optflags|=THREADS;
+ threads=convtemp;
+ }
+ break;
+ case 'm':
+ if((convtemp = strtoll(optarg, NULL, 10))==0)
+ {
+ errflags|=MEMSIZE;
+ perror("Error with -m: ");
+ }
+ else
+ {
+ optflags|=MEMSIZE;
+ memory=convtemp*1024*1024;
+ }
+ break;
+ case 'h':
+ case '?':
+ default:
+ usage();
+ }
+ }
+
+ if(errflags>0)
+ {
+ usage();
+ }
+ if(optflags & THREADS)
+ {
+ printf("Threads: %d\n", threads);
+ }
+ if(optflags & MEMSIZE)
+ {
+ printf("Memsize: %llu\n", memory);
+ }
+
+ for(i=0; i<threads; i++)
+ {
+ switch(pid=fork())
+ {
+ case -1:
+ perror("fork()");
+ break;
+ case 0:
+ if(optflags&MEMSIZE)
+ testMemory(memory/threads);
+ else
+ testCPU();
+ break;
+ }
+ }
+ for(i=0; i<threads; i++)
+ {
+ wait(&wstatus);
+ }
+
+ return 0;
+}
diff --git a/stress.h b/stress.h
new file mode 100644
index 0000000..b1cfb88
--- /dev/null
+++ b/stress.h
@@ -0,0 +1,27 @@
+#ifndef _STRESS_H
+#define _STRESS_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <unistd.h>
+#include <math.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+extern int errno;
+
+#ifndef LDBL_MAX
+#define LDBL_MAX __LDBL_MAX__
+#endif
+
+#ifndef LDBL_EPSILON
+#define LDBL_EPSILON __LDBL_EPSILON__
+#endif
+
+#define THREADS 0x1
+#define MEMSIZE 0x2
+
+void testCPU(void);
+void testMemory(unsigned long long);
+void usage(void);
+#endif