-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lars T Hansen
committed
Apr 23, 2024
1 parent
beae23d
commit 735d877
Showing
8 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rollup | ||
rollup2 | ||
rollupchild | ||
rollupchild2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CFLAGS=-Wall -std=c89 | ||
.PHONY: all | ||
|
||
all: rollup rollup2 rollupchild rollupchild2 | ||
|
||
rollupchild2: rollupchild | ||
cp rollupchild rollupchild2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Run this with SONARTEST_ROLLUP=1 and --rollup --batchless. | ||
If you grep the sonar output for ',cmd=rollup,' there should be 23 lines. | ||
Of those, there should be eight that have ',rolledup=1' and none that have any other rollup fields. | ||
(This code is -std=c89, try to keep it that way.) | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
int main(int argc, char** argv) { | ||
long depth; | ||
pid_t c1, c2; | ||
if (argc < 2) { | ||
fprintf(stderr, "Usage: %s depth\n", argv[0]); | ||
exit(1); | ||
} | ||
errno = 0; | ||
depth = strtol(argv[1], NULL, 10); | ||
if (errno != 0 || depth < 0 || depth > 10) { | ||
fprintf(stderr, "Bad depth\n"); | ||
exit(1); | ||
} | ||
again: | ||
/* in Parent */ | ||
c1 = fork(); | ||
if (c1 == -1) { | ||
perror("Forking child"); | ||
exit(1); | ||
} | ||
if (c1 > 0) { | ||
/* in Parent */ | ||
c2 = fork(); | ||
if (c2 == -1) { | ||
perror("Forking child"); | ||
exit(1); | ||
} | ||
if (c2 > 0) { | ||
/* in Parent */ | ||
/* printf("Waiting %d\n", getpid()); */ | ||
wait(NULL); | ||
wait(NULL); | ||
} else { | ||
/* in C2 */ | ||
if (depth-- > 0) { | ||
goto again; | ||
} | ||
/* printf("Sleeping %d\n", getpid()); */ | ||
sleep(10); | ||
} | ||
} else { | ||
/* in C1 */ | ||
if (depth-- > 0) { | ||
goto again; | ||
} | ||
/* printf("Sleeping %d\n", getpid()); */ | ||
sleep(10); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# | ||
# Test these aspects of the process rollup algorithm: | ||
# - only leaf processes are rolled up | ||
# - only siblings of the same parent are rolled up | ||
# | ||
# To do this on a non-slurm system we run --rollup --batchless with an override to allow that. | ||
# | ||
# This requires a (probably) 1.6x or later Rust/Cargo toolchain to build Sonar and `make` + any C89 | ||
# or later C compiler to build the C code. | ||
|
||
set -e | ||
|
||
( cd .. ; cargo build ) | ||
make --quiet | ||
|
||
echo "This takes about 10s" | ||
./rollup 3 & | ||
sleep 3 | ||
output=$(SONARTEST_ROLLUP=1 ../target/debug/sonar ps --rollup --batchless --exclude-system-jobs) | ||
matches=$(grep ,cmd=rollup, <<< $output) | ||
rolled=$(grep ,rolledup=1 <<< $matches) | ||
rolled2=$(grep ,rolledup= <<< $matches) | ||
if [[ $(wc -l <<< $matches) != 23 ]]; then | ||
echo "Bad number of matching lines" | ||
exit 1 | ||
fi | ||
if [[ $(wc -l <<< $rolled) != 8 ]]; then | ||
echo "Bad number of rolled-up lines with value 1" | ||
exit 1 | ||
fi | ||
if [[ $(wc -l <<< $rolled2) != 8 ]]; then | ||
echo "Bad number of rolled-up lines - some have a value other than 1" | ||
exit 1 | ||
fi | ||
echo Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* Run this with SONARTEST_ROLLUP=1 and --rollup --batchless. | ||
This will fork off a 9 child processes (rollupchild x 5 and rollupchild2 x 4) that are the | ||
same except for the name, all of which will wait 10s. Sonar, run meanwhile, should rollup | ||
the children with the same name only. Since the rollup field represents n-1 processes, | ||
the count for rollupchild should be 4 and for rollupchild2 should be 3. | ||
(This code is -std=c89, try to keep it that way.) | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
#define TYPE1 5 | ||
#define TYPE2 4 | ||
|
||
int main(int argc, char** argv) { | ||
int i; | ||
for ( i=0 ; i < TYPE1+TYPE2 ; i++ ) { | ||
switch (fork()) { | ||
case -1: | ||
perror("Forking child"); | ||
exit(1); | ||
case 0: | ||
if (i < TYPE1) { | ||
execl("rollupchild", "rollupchild", NULL); | ||
fprintf(stderr, "Failed to exec child\n"); | ||
exit(1); | ||
} else { | ||
execl("rollupchild2", "rollupchild2", NULL); | ||
fprintf(stderr, "Failed to exec child 2\n"); | ||
exit(1); | ||
} | ||
} | ||
} | ||
for ( i=0 ; i < TYPE1+TYPE2 ; i++ ) { | ||
wait(NULL); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# | ||
# Test these aspects of the process rollup algorithm: | ||
# - only siblings with the same name are rolled up | ||
# | ||
# To do this on a non-slurm system we run --rollup --batchless with an override to allow that. | ||
# | ||
# This requires a (probably) 1.6x or later Rust/Cargo toolchain to build Sonar and `make` + any C89 | ||
# or later C compiler to build the C code. | ||
|
||
set -e | ||
|
||
( cd .. ; cargo build ) | ||
make --quiet | ||
|
||
echo "This takes about 10s" | ||
./rollup2 3 & | ||
sleep 3 | ||
output=$(SONARTEST_ROLLUP=1 ../target/debug/sonar ps --rollup --batchless --exclude-system-jobs) | ||
# Grep will exit with code 1 if no lines are matched | ||
matches1=$(grep -E ',cmd=rollupchild,.*,rolledup=4' <<< $output) | ||
matches2=$(grep -E ',cmd=rollupchild2,.*,rolledup=3' <<< $output) | ||
echo Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* See rollup2.c */ | ||
|
||
#include <unistd.h> | ||
|
||
int main(int argc, char** argv) { | ||
sleep(10); | ||
return 0; | ||
} |