Skip to content

Commit

Permalink
chore(tests): add tests for CI automation testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Apr 23, 2024
1 parent f9a4563 commit aa1bbd5
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build & Test

on:
pull_request:
branches:
- '*'
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and Test
run: |
./configure && make && make test && export LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH && make run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
Makefile
lib/
objs/
bin/
build/
conf/melon.conf
55 changes: 54 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ generate_Makefile() {
echo "compile: MKDIR \$(OBJS) \$(MELONSO) \$(MELONA)" >> Makefile
fi
echo "clean:" >> Makefile
echo -e "\trm -fr objs lib Makefile" >> Makefile
echo -e "\trm -fr objs lib bin Makefile" >> Makefile
echo "MKDIR :" >> Makefile
echo -e "\ttest -d objs || mkdir objs" >> Makefile
echo -e "\ttest -d lib || mkdir lib" >> Makefile
Expand Down Expand Up @@ -462,6 +462,59 @@ generate_Makefile() {
echo -e "\ttest -d $install_path/conf || cp -fr conf $install_path" >> Makefile
echo -e "\ttest -d $melang_script_path/trace || cp -fr trace $melang_script_path" >> Makefile

echo "TEST_MKDIR: " >> Makefile
echo -e "\ttest -d bin || mkdir -p bin" >> Makefile
for fname in ${select_files[@]}
do
fname=$(echo $fname | sed 's/^src\/mln_//')
binname=`echo $fname | cut -d '.' -f 1`
fname="t/$fname"
if [ -f $fname ]; then
echo -n "bin/$binname : " >> Makefile
for header in `cpp -MM -MG $fname 2> /dev/null`
do
suffix=`echo $header | cut -d '.' -f 2`
if [ $suffix = 'c' ]; then
echo -n $header >> Makefile
echo -n " " >> Makefile
continue
fi
if [ $suffix != 'h' ]; then
continue
fi
test -e include/$header && echo -n "include/$header " >> Makefile
done
echo "" >> Makefile

echo -e "\t\$(CC) -o \$@ $fname $debug -Iinclude -Llib -lmelon" >> Makefile
fi
done
echo -e "BINS = \\" >> Makefile
for fname in ${select_files[@]}
do
fname=$(echo $fname | sed 's/^src\/mln_//')
binname="bin/"`echo $fname | cut -d '.' -f 1`
fname="t/$fname"
if [ -f $fname ]; then
echo " $binname \\" >> Makefile
fi
done
echo "" >> Makefile
echo "test: TEST_MKDIR \$(BINS)" >> Makefile
echo "" >> Makefile

echo "run:" >> Makefile
for fname in ${select_files[@]}
do
fname=$(echo $fname | sed 's/^src\/mln_//')
binname="bin/"`echo $fname | cut -d '.' -f 1`
fname="t/$fname"
if [ -f $fname ]; then
echo -e "\t./$binname && \\" >> Makefile
fi
done
echo "echo 'Done'" >> Makefile

for fname in ${select_files[@]}
do
objname=`basename $fname | cut -d '.' -f 1`".o"
Expand Down
33 changes: 33 additions & 0 deletions t/aes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include "mln_string.h"
#include "mln_aes.h"

int main(int argc, char *argv[])
{
mln_aes_t a;
char p[] = "1234567890123456";
mln_string_t s;

if (mln_aes_init(&a, (mln_u8ptr_t)"abcdefghijklmnop", M_AES_128) < 0) {
fprintf(stderr, "aes init failed\n");
return -1;
}

mln_string_set(&s, p);
if (mln_aes_encrypt(&a, s.data) < 0) {
fprintf(stderr, "aes encrypt failed\n");
return -1;
}
write(STDOUT_FILENO, s.data, s.len);
write(STDOUT_FILENO, "\n", 1);

if (mln_aes_decrypt(&a, s.data) < 0) {
fprintf(stderr, "aes decrypt failed\n");
return -1;
}
write(STDOUT_FILENO, s.data, s.len);
write(STDOUT_FILENO, "\n", 1);

return 0;
}
33 changes: 33 additions & 0 deletions t/base64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include "mln_string.h"
#include "mln_base64.h"

int main(int argc, char *argv[])
{
mln_string_t text = mln_string("Hello");
mln_string_t tmp;
mln_u8ptr_t p1, p2;
mln_uauto_t len1, len2;

if (mln_base64_encode(text.data, text.len, &p1, &len1) < 0) {
fprintf(stderr, "encode failed\n");
return -1;
}
mln_string_nset(&tmp, p1, len1);
write(STDOUT_FILENO, tmp.data, tmp.len);
write(STDOUT_FILENO, "\n", 1);

if (mln_base64_decode(p1, len1, &p2, &len2) < 0) {
fprintf(stderr, "decode failed\n");
return -1;
}
mln_string_nset(&tmp, p2, len2);
write(STDOUT_FILENO, tmp.data, tmp.len);
write(STDOUT_FILENO, "\n", 1);

mln_base64_free(p1);
mln_base64_free(p2);

return 0;
}

0 comments on commit aa1bbd5

Please sign in to comment.