Skip to content

Commit c11dddc

Browse files
committed
rt: Move test functions to rust_test_helpers.cpp
1 parent 260d74d commit c11dddc

File tree

3 files changed

+97
-77
lines changed

3 files changed

+97
-77
lines changed

Diff for: mk/rt.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ RUNTIME_CXXS_$(1) := \
7575
rt/boxed_region.cpp \
7676
rt/arch/$$(HOST_$(1))/context.cpp \
7777
rt/arch/$$(HOST_$(1))/gpr.cpp \
78-
rt/rust_android_dummy.cpp
78+
rt/rust_android_dummy.cpp \
79+
rt/rust_test_helpers.cpp
7980

8081
RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
8182

Diff for: src/rt/rust_builtin.cpp

-76
Original file line numberDiff line numberDiff line change
@@ -589,50 +589,6 @@ rust_log_console_off() {
589589
log_console_off(task->kernel->env);
590590
}
591591

592-
extern "C" CDECL lock_and_signal *
593-
rust_dbg_lock_create() {
594-
return new lock_and_signal();
595-
}
596-
597-
extern "C" CDECL void
598-
rust_dbg_lock_destroy(lock_and_signal *lock) {
599-
assert(lock);
600-
delete lock;
601-
}
602-
603-
extern "C" CDECL void
604-
rust_dbg_lock_lock(lock_and_signal *lock) {
605-
assert(lock);
606-
lock->lock();
607-
}
608-
609-
extern "C" CDECL void
610-
rust_dbg_lock_unlock(lock_and_signal *lock) {
611-
assert(lock);
612-
lock->unlock();
613-
}
614-
615-
extern "C" CDECL void
616-
rust_dbg_lock_wait(lock_and_signal *lock) {
617-
assert(lock);
618-
lock->wait();
619-
}
620-
621-
extern "C" CDECL void
622-
rust_dbg_lock_signal(lock_and_signal *lock) {
623-
assert(lock);
624-
lock->signal();
625-
}
626-
627-
typedef void *(*dbg_callback)(void*);
628-
629-
extern "C" CDECL void *
630-
rust_dbg_call(dbg_callback cb, void *data) {
631-
return cb(data);
632-
}
633-
634-
extern "C" CDECL void rust_dbg_do_nothing() { }
635-
636592
extern "C" CDECL void
637593
rust_dbg_breakpoint() {
638594
BREAKPOINT_AWESOME;
@@ -844,38 +800,6 @@ rust_readdir() {
844800

845801
#endif
846802

847-
// These functions are used in the unit tests for C ABI calls.
848-
849-
extern "C" CDECL uint32_t
850-
rust_dbg_extern_identity_u32(uint32_t u) {
851-
return u;
852-
}
853-
854-
extern "C" CDECL uint64_t
855-
rust_dbg_extern_identity_u64(uint64_t u) {
856-
return u;
857-
}
858-
859-
struct TwoU64s {
860-
uint64_t one;
861-
uint64_t two;
862-
};
863-
864-
extern "C" CDECL TwoU64s
865-
rust_dbg_extern_identity_TwoU64s(TwoU64s u) {
866-
return u;
867-
}
868-
869-
extern "C" CDECL double
870-
rust_dbg_extern_identity_double(double u) {
871-
return u;
872-
}
873-
874-
extern "C" CDECL char
875-
rust_dbg_extern_identity_u8(char u) {
876-
return u;
877-
}
878-
879803
extern "C" rust_env*
880804
rust_get_rt_env() {
881805
rust_task *task = rust_get_current_task();

Diff for: src/rt/rust_test_helpers.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Helper functions used only in tests
12+
13+
#include "rust_sched_loop.h"
14+
#include "rust_task.h"
15+
#include "rust_util.h"
16+
#include "rust_scheduler.h"
17+
#include "sync/timer.h"
18+
#include "sync/rust_thread.h"
19+
#include "rust_abi.h"
20+
21+
// These functions are used in the unit tests for C ABI calls.
22+
23+
extern "C" CDECL uint32_t
24+
rust_dbg_extern_identity_u32(uint32_t u) {
25+
return u;
26+
}
27+
28+
extern "C" CDECL uint64_t
29+
rust_dbg_extern_identity_u64(uint64_t u) {
30+
return u;
31+
}
32+
33+
struct TwoU64s {
34+
uint64_t one;
35+
uint64_t two;
36+
};
37+
38+
extern "C" CDECL TwoU64s
39+
rust_dbg_extern_identity_TwoU64s(TwoU64s u) {
40+
return u;
41+
}
42+
43+
extern "C" CDECL double
44+
rust_dbg_extern_identity_double(double u) {
45+
return u;
46+
}
47+
48+
extern "C" CDECL char
49+
rust_dbg_extern_identity_u8(char u) {
50+
return u;
51+
}
52+
53+
extern "C" CDECL lock_and_signal *
54+
rust_dbg_lock_create() {
55+
return new lock_and_signal();
56+
}
57+
58+
extern "C" CDECL void
59+
rust_dbg_lock_destroy(lock_and_signal *lock) {
60+
assert(lock);
61+
delete lock;
62+
}
63+
64+
extern "C" CDECL void
65+
rust_dbg_lock_lock(lock_and_signal *lock) {
66+
assert(lock);
67+
lock->lock();
68+
}
69+
70+
extern "C" CDECL void
71+
rust_dbg_lock_unlock(lock_and_signal *lock) {
72+
assert(lock);
73+
lock->unlock();
74+
}
75+
76+
extern "C" CDECL void
77+
rust_dbg_lock_wait(lock_and_signal *lock) {
78+
assert(lock);
79+
lock->wait();
80+
}
81+
82+
extern "C" CDECL void
83+
rust_dbg_lock_signal(lock_and_signal *lock) {
84+
assert(lock);
85+
lock->signal();
86+
}
87+
88+
typedef void *(*dbg_callback)(void*);
89+
90+
extern "C" CDECL void *
91+
rust_dbg_call(dbg_callback cb, void *data) {
92+
return cb(data);
93+
}
94+
95+
extern "C" CDECL void rust_dbg_do_nothing() { }

0 commit comments

Comments
 (0)