Skip to content

Commit

Permalink
test: added test.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Garic152 committed Jun 26, 2024
1 parent 5374c89 commit 9d7dfdd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/ringbuf.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#include "../include/ringbuf.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

void ringbuffer_init(rbctx_t *context, void *buffer_location, size_t buffer_size)
{
/* your solution here */
void ringbuffer_init(rbctx_t *context, void *buffer_location,
size_t buffer_size) {
context->begin = (uint8_t *)buffer_location;
context->end = context->begin + buffer_size;
context->read = context->begin;
context->write = context->begin;
}

int ringbuffer_write(rbctx_t *context, void *message, size_t message_len)
{
/* your solution here */
}
int ringbuffer_write(rbctx_t *context, void *message, size_t message_len) {
if (message_len >= context->end - context->begin) {
return OUTPUT_BUFFER_TOO_SMALL;
}

int ringbuffer_read(rbctx_t *context, void *buffer, size_t *buffer_len)
{
/* your solution here */
for (size_t i = 1; i <= message_len; i++) {
context->begin[i] = ((char *)message)[i];
context->write += 1;
}
return SUCCESS;
}

void ringbuffer_destroy(rbctx_t *context)
{
/* your solution here */
int ringbuffer_read(rbctx_t *context, void *buffer, size_t *buffer_len) {
/* your solution here */
}

void ringbuffer_destroy(rbctx_t *context) { /* your solution here */ }
41 changes: 41 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
make clean
make all

# Initialize counters
passed=0
failed=0
summary_file=$(mktemp)

# Iterate over the test executables
for test_executable in $(find build/ -type f \( -name "test" -o -name "test_*" \)); do
if [ -x "$test_executable" ]; then
echo -e "\n===> \033[0;34mRUNNING\033[0m $test_executable <===\n"
"$test_executable"
if [ $? -eq 0 ]; then
echo "echo -e \"\033[0;32mPASSED\033[0m --- $test_executable\"" >> $summary_file
passed=$((passed+1))
else
echo "echo -e \"\033[0;31mFAILED\033[0m --- $test_executable\"" >> $summary_file
failed=$((failed+1))
fi
fi
done

total=$((passed + failed))

echo -e "===SUMMARY===\n"

source $summary_file
rm -rf $summary_file

echo "---"

if [ $failed -ne 0 ]; then
echo -e "\033[0;31mFAILED:\033[0m $failed / $total"
fi
if [ $passed -ne 0 ]; then
echo -e "\033[0;32mPASSED:\033[0m $passed / $total"
fi

exit $failed

0 comments on commit 9d7dfdd

Please sign in to comment.