#include <assert.h>
-void p_exit(i8 exit_code) {
+void p_impl_exit(i8 exit_code) {
exit(exit_code);
}
*/
void p_delay(u64 time);
-void p_exit(i8 exit_code);
+#ifdef LRTS_TESTS
+#define p_exit(exit_code)
+#else
+/* this is just a wrapper macro around exit
+ * to allow tests to undefine it and do nothing on exit */
+#define p_exit(exit_code) p_impl_exit(exit_code)
+#endif
+
+void p_impl_exit(i8 exit_code);
/**
struct t_command_queue t_command_queue;
-void t_command_queue_process(void) {
+u32 t_command_queue_process(void) {
+ return 0;
}
lrts_bool t_command_exec(struct t_command *c) {
if (t_command_queue.buffer[t_command_queue.write_idx].type != T_COMMAND_NONE) {
u_log(U_LOG_CRIT, "Command queue overflow!\n");
p_exit(P_EXIT_FAIL);
+ return;
}
t_command_queue.buffer[t_command_queue.write_idx++] = c;
struct t_command {
enum t_command_type type;
enum t_command_flags flags;
+ u32 run_at_tick;
union t_command_data d;
};
extern struct t_command_queue t_command_queue;
-/* runs the command queue */
-void t_command_queue_process(void);
+/* runs the command queue
+ * returns number of commands run
+ * commands are only run if the tick in t_command <= current tick
+ **/
+u32 t_command_queue_process(void);
/* executes a command. Returns true if command was executed. */
lrts_bool t_command_exec(struct t_command *c);
#define LRTS_IMPL
#define LRTS_RENDERER_TESTS
+#define LRTS_TESTS
#include "lrts.h"
#include "p_platform.h"
+
#include "tests/t_defs.h"
#ifdef LRTS_IMPL
#include "tests/t_args.c"
#include "tests/t_arena.c"
#include "tests/t_math.c"
+#include "tests/t_command.c"
#endif
+
int main(int argc, char **argv) {
p_io_init();
T_TESTCASE("fixed-point-macro", t_test_fp_macros);
T_TESTCASE("fixed-point-sqrt", t_test_fp_sqrt);
+ T_TESTCASE("command push", test_t_command_push);
+
T_TESTEND("lrts test");
p_io_finish();
--- /dev/null
+#include "t_defs.h"
+#include "../t_command.h"
+
+int test_t_command_push(void) {
+ struct t_command t;
+ u32 i = 0;
+
+ t.type = T_COMMAND_MOVE_CAMERA;
+ t_command_push(t);
+ T_ASSERT(t_command_queue.write_idx == 1, ("write index moved\n"));
+ T_ASSERT(t_command_queue.buffer[0].type == T_COMMAND_MOVE_CAMERA, ("command written\n"));
+
+ for (i = 0; i < T_COMMANDS_MAX+1; i++) {
+ t_command_push(t);
+ }
+
+ T_ASSERT(t_command_queue.write_idx == 0, ("write index out of bounds"));
+
+ return 0;
+}