1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 23:59:41 +02:00
audacity/tests/octave/run_test.m
Max Maisel 6da48db127 Start work on new Loudness effect
This is based on my old loudness effect prototype which was included
in the Normalize effect.

Create all source files and add them to all build systems.
Currently, the effect only consists of a GUI mockup.
Create Octave+mod-script-pipe based dummy unit-test as well.
2019-11-22 19:42:32 +01:00

175 lines
3.6 KiB
Matlab
Executable File

#!/usr/bin/octave -qf
## Audacity Octave unit test runner
#
# Max Maisel
#
if !(nargin == 1 || nargin == 2)
printf("Usage: ./testbench.m <test-file.m> [-v]\n");
exit(2);
end
arg_list = argv();
if exist(arg_list{1}, "file") != 2
printf("Specified test file does not exist!\n");
exit(2);
end
global VERBOSE;
VERBOSE=0;
if nargin == 2
if strcmp(arg_list{2}, "-v") == 1
VERBOSE=1;
else
printf("Unknown argument %s. Abort!", arg_list{2});
exit(2);
end
end
## Initialization and helper functions
UID=num2str(getuid());
PIPE_TO_PATH=strcat("/tmp/audacity_script_pipe.to.", UID);
PIPE_FROM_PATH=strcat("/tmp/audacity_script_pipe.from.", UID);
TMP_FILENAME=strcat(pwd(), "/tmp.wav");
printf("Open scripting pipes, this may freeze if Audacity does not run...\n");
global PIPE_TO;
global PIPE_FROM;
global PRINT_COMMANDS;
PRINT_COMMANDS=false;
PIPE_TO=fopen(PIPE_TO_PATH, "w");
PIPE_FROM=fopen(PIPE_FROM_PATH, "r");
## aud-do helper function
function aud_do(command)
global PIPE_TO;
global PIPE_FROM;
global PRINT_COMMANDS;
if PRINT_COMMANDS
puts(command);
end
fwrite(PIPE_TO, command);
fflush(PIPE_TO);
do
string = fgets(PIPE_FROM);
if PRINT_COMMANDS
puts(string);
end
fflush(stdout);
until strncmp(string, "BatchCommand finished:", length("BatchCommand finished:"));
end
## Float equal comparison helper
function [ret] = float_eq(x, y, eps=0.001)
ret = abs(x - y) < eps;
end
## Test report helper
global TESTS_FAILED;
global TESTS_RUN;
global TESTS_SKIPPED;
global CURRENT_TEST;
TESTS_FAILED = 0;
TESTS_RUN = 0;
TESTS_SKIPPED = 0;
CURRENT_TEST="";
function plot_failure(x, y)
global VERBOSE;
if VERBOSE == 0
return;
end
figure(1)
plot(x, 'r')
hold on
plot(y, 'b')
plot(log10(abs(x-y)), 'g')
hold off
legend("Audacity", "Octave", "log-delta", "location", "southeast")
input("Press enter to continue", "s")
end
function do_test_equ(x, y, msg, eps=0.001, skip = false)
cmp = all(all(float_eq(x, y, eps)));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_neq(x, y, msg, eps=0.001, skip = false)
cmp = all(all(!float_eq(x, y, eps)));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_gte(x, y, msg, skip = false)
cmp = all(all(x >= y));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_lte(x, y, msg, skip = false)
cmp = all(all(x <= y));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function result = do_test(result, msg, skip = false)
global TESTS_RUN;
global TESTS_FAILED;
global TESTS_SKIPPED;
global CURRENT_TEST;
TESTS_RUN = TESTS_RUN + 1;
suffix = "";
if !strcmp(msg, "")
suffix = cstrcat(" - ", msg);
end
if skip
TESTS_SKIPPED = TESTS_SKIPPED + 1;
printf(cstrcat("[Skip]: ", CURRENT_TEST, suffix, "\n"));
result = 1;
else
if result
printf(cstrcat("[Success]: ", CURRENT_TEST, suffix, "\n"));
return;
else
TESTS_FAILED = TESTS_FAILED + 1;
printf(cstrcat("[Failed]: ", CURRENT_TEST, suffix, "\n"));
return;
end
end
end
## Run tests
printf("Starting tests...\n");
source(arg_list{1});
## Cleanup and result reporting
unlink(TMP_FILENAME);
fclose(PIPE_FROM);
fclose(PIPE_TO);
printf("%d tests run, %d tests failed, %d tests skipped\n", TESTS_RUN, TESTS_FAILED, TESTS_SKIPPED);
if TESTS_FAILED != 0
printf("Some tests failed!\n");
if VERBOSE == 0
printf("Re-run with -v option for details.\n");
end
exit(1);
elseif TESTS_SKIPPED != 0
printf("Some tests were skipped!\n");
else
printf("All tests succeeded!\n");
end
exit(0)