Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fix #14

Merged
merged 6 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/bad_rank.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "../mimpi.h"
#include "test.h"

int main()
{
Expand All @@ -13,9 +14,9 @@ int main()
char number = '1';
int const tag = 1;

assert(MIMPI_ERROR_NO_SUCH_RANK == MIMPI_Send(&number, sizeof(number), world_size + world_rank, tag));
assert(MIMPI_ERROR_NO_SUCH_RANK == MIMPI_Recv(&number, sizeof(number), world_size + world_rank, tag));
test_assert(MIMPI_ERROR_NO_SUCH_RANK == MIMPI_Send(&number, sizeof(number), world_size + world_rank, tag));
test_assert(MIMPI_ERROR_NO_SUCH_RANK == MIMPI_Recv(&number, sizeof(number), world_size + world_rank, tag));

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/bare_barrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <assert.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

#define WRITE_VAR "CHANNELS_WRITE_DELAY"

Expand All @@ -23,5 +24,5 @@ int main(int argc, char **argv)
assert(res == 0);
printf("after\n");
MIMPI_Finalize();
return 0;
return test_success();
}
9 changes: 5 additions & 4 deletions examples/bare_reduce.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <assert.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

#define WRITE_VAR "CHANNELS_WRITE_DELAY"

Expand Down Expand Up @@ -36,7 +37,7 @@ int main(int argc, char **argv)
assert(recv_data);
ASSERT_MIMPI_OK(MIMPI_Reduce(data, recv_data, data_size, MIMPI_SUM, 0));
for (int i = 1; i < data_size; ++i)
assert(recv_data[i] == recv_data[0]);
test_assert(recv_data[i] == recv_data[0]);
printf("Number: %d\n", recv_data[0]);
fflush(stdout);
free(recv_data);
Expand All @@ -45,14 +46,14 @@ int main(int argc, char **argv)
{
ASSERT_MIMPI_OK(MIMPI_Reduce(data, NULL, data_size, MIMPI_SUM, 0));
}
assert(data[0] == 1);
test_assert(data[0] == 1);
for (int i = 1; i < data_size; ++i)
assert(data[i] == data[0]);
test_assert(data[i] == data[0]);
free(data);

int res = unsetenv(WRITE_VAR);
assert(res == 0);

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/barrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand All @@ -20,5 +21,5 @@ int main(int argc, char **argv)
}

MIMPI_Finalize();
return 0;
return test_success();
}
7 changes: 4 additions & 3 deletions examples/big_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

char data[21372137];

Expand All @@ -20,17 +21,17 @@ int main(int argc, char **argv)

ASSERT_MIMPI_OK(MIMPI_Send(data, sizeof(data), 1, tag));
for (int i = 0; i < sizeof(data); i += 789) {
assert(data[789] == 42);
test_assert(data[789] == 42);
}
}
else if (world_rank == 1)
{
ASSERT_MIMPI_OK(MIMPI_Recv(data, sizeof(data), 0, tag));
for (int i = 0; i < sizeof(data); i += 789) {
assert(data[789] == 42);
test_assert(data[789] == 42);
}
}

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <assert.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

#define WRITE_VAR "CHANNELS_WRITE_DELAY"

Expand All @@ -29,5 +30,5 @@ int main(int argc, char **argv)
assert(res == 0);

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/deadlock.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdbool.h>
#include "../mimpi.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand All @@ -18,5 +19,5 @@ int main(int argc, char **argv)
assert(MIMPI_Recv(&number, 1, partner_rank, 1) == MIMPI_ERROR_DEADLOCK_DETECTED);

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/external_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unistd.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

#define DESCRIPTOR_FROM_ABOVE 7
#define MSG "Process 1 received number from process 0\n"
Expand Down Expand Up @@ -36,5 +37,5 @@ int main(int argc, char **argv)
}

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/hello.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "../mimpi.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand All @@ -12,5 +13,5 @@ int main(int argc, char **argv)
printf("Hello World from process %d of %d\n", process_rank, size_of_cluster);

MIMPI_Finalize();
return 0;
return test_success();
}
7 changes: 4 additions & 3 deletions examples/obstruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

char data[21372137];

Expand All @@ -19,7 +20,7 @@ int main(int argc, char **argv)

ASSERT_MIMPI_OK(MIMPI_Send(data, sizeof(data), 1, tag));
for (int i = 0; i < sizeof(data); i += 789) {
assert(data[i] == 42);
test_assert(data[i] == 42);
}
ASSERT_MIMPI_OK(MIMPI_Barrier());
}
Expand All @@ -28,12 +29,12 @@ int main(int argc, char **argv)
ASSERT_MIMPI_OK(MIMPI_Barrier());
ASSERT_MIMPI_OK(MIMPI_Recv(data, sizeof(data), 0, tag));
for (int i = 0; i < sizeof(data); i += 789) {
assert(data[i] == 42);
test_assert(data[i] == 42);
}
} else {
ASSERT_MIMPI_OK(MIMPI_Barrier());
}

MIMPI_Finalize();
return 0;
return test_success();
}
7 changes: 4 additions & 3 deletions examples/pipe_closed.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <time.h>
#include <unistd.h>
#include "../mimpi.h"
#include "test.h"

#define NS_PER_1_MS 1 ## 000 ## 000

Expand All @@ -24,12 +25,12 @@ int main(int argc, char **argv)
res = nanosleep(&ts, &ts);
} while (res && errno == EINTR);
} else if (world_rank == 1) {
assert(MIMPI_Recv(&number, 1, 0, tag) == MIMPI_ERROR_REMOTE_FINISHED);
assert(MIMPI_Send(&number, 1, 0, tag) == MIMPI_ERROR_REMOTE_FINISHED);
test_assert(MIMPI_Recv(&number, 1, 0, tag) == MIMPI_ERROR_REMOTE_FINISHED);
test_assert(MIMPI_Send(&number, 1, 0, tag) == MIMPI_ERROR_REMOTE_FINISHED);
printf("Process 1 received number %d from process 0\n", number);
}

// Process with rank 0 finishes before rank 1 gets its message.
MIMPI_Finalize();
return 0;
return test_success();
}
5 changes: 3 additions & 2 deletions examples/reduction.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdint.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

static unsigned factorial(unsigned n) {
if (n == 0 || n == 1) {
Expand Down Expand Up @@ -44,11 +45,11 @@ int main(int argc, char **argv)
// if (recv_data[k] != result) {
// fprintf(stderr, "MISMATCH: op_idx %i, root %i, k=%i: expected %i, got %i.\n", i, root, k, result, recv_data[k]);
// }
assert(recv_data[k] == result);
test_assert(recv_data[k] == result);
}
}
}

MIMPI_Finalize();
return 0;
return test_success();
}
7 changes: 4 additions & 3 deletions examples/self_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "../mimpi.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand All @@ -12,9 +13,9 @@ int main(int argc, char **argv)
char number = '1';
int const tag = 1;

assert(MIMPI_ERROR_ATTEMPTED_SELF_OP == MIMPI_Send(&number, sizeof(number), world_rank, tag));
assert(MIMPI_ERROR_ATTEMPTED_SELF_OP == MIMPI_Recv(&number, sizeof(number), world_rank, tag));
test_assert(MIMPI_ERROR_ATTEMPTED_SELF_OP == MIMPI_Send(&number, sizeof(number), world_rank, tag));
test_assert(MIMPI_ERROR_ATTEMPTED_SELF_OP == MIMPI_Recv(&number, sizeof(number), world_rank, tag));

MIMPI_Finalize();
return 0;
return test_success();
}
3 changes: 2 additions & 1 deletion examples/send_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand All @@ -24,5 +25,5 @@ int main(int argc, char **argv)
}

MIMPI_Finalize();
return 0;
return test_success();
}
17 changes: 17 additions & 0 deletions examples/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef TEST_H
#define TEST_H
#include <unistd.h>
#include <assert.h>

#define SUCCESS_MARKER "<<success>>\n"

int test_success()
{
// below unchecked syscall return code
write(STDERR_FILENO, SUCCESS_MARKER, sizeof(SUCCESS_MARKER));
return 0;
}

#define test_assert(expr) assert(expr && "<<error>>")

#endif // TEST_H
3 changes: 2 additions & 1 deletion examples/writers_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Refers to <usprawnienie2> TODO: przenazwać to.
#include <assert.h>
#include "../mimpi.h"
#include "mimpi_err.h"
#include "test.h"

int main(int argc, char **argv)
{
Expand Down Expand Up @@ -51,5 +52,5 @@ int main(int argc, char **argv)
}

MIMPI_Finalize();
return 0;
return test_success();
}
39 changes: 39 additions & 0 deletions run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

# Print help usage if there are fewer then 3 positional arguments
if [ $# -lt 3 ] ; then
echo "Usage: $0 TIMEOUT NUM_OF_WORKERS PATH_TO_PROG [ADDITIONAL_ARGS]"
exit 1
fi

# Read important values from positional args into named vars
TIMEOUT=$1
NUM_OF_WORKERS=$2
shift 2

# Create temporary file
tmp_file=$(mktemp)

# Invoke mimpirun with appropriate timeout and arguments
# "|| true" used to ignore ./mimpirun return code
timeout "$TIMEOUT" ./mimpirun "$NUM_OF_WORKERS" "$@" 2> "$tmp_file" || true

result=0

# Check if all workers finished sucessfully
# - num of <<success>> is equeal to number of created workers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equal*

test "$(grep -c '<<success>>' "$tmp_file")" -ne "$NUM_OF_WORKERS" && result=3

# Check if error has been detected - <<error>> was found in stderr
grep "<<error>>" "$tmp_file" > /dev/null && result=2

# Print stderr in case of error
test "$result" -ne 0 && cat "$tmp_file" >&2

# Remove temporary file
rm "$tmp_file"

# Exit with appropraite return code
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appropriate

exit "$result"
Loading