Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Mar 13, 2023
1 parent d7232ec commit b9d0c7a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 28 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ add_definitions(
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMAX_REGS_SIZE=256
-DMAX_VM_COUNT=255
-DMAX_SYMBOLS_COUNT=1000
-DMAX_SYMBOLS_COUNT=2000
-DMRBC_CONVERT_CRLF
-DMRBC_USE_MATH
-DPICORBC_PTR_SIZE=4
)
if(PRK_NO_MSC)
add_definitions(-DPRK_NO_MSC)
if(PICORUBY_NO_MSC)
add_definitions(-DPICORUBY_NO_MSC)
else()
add_definitions(-DPICORUBY_MSC_FLASH)
endif()

#####################################################
Expand All @@ -30,7 +32,7 @@ set (PRK_BUILDDATE ${CMAKE_BUILDDATE})
set (PRK_REVISION ${CMAKE_REVISION})
configure_file ("${CMAKE_SOURCE_DIR}/include/version.h.in" "${CMAKE_SOURCE_DIR}/include/version.h")

if(PRK_NO_MSC)
if(PICORUBY_NO_MSC)
project("prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-no_msc")
else()
project("prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
Expand All @@ -43,6 +45,7 @@ file(GLOB SRCS src/*.c)
add_executable(${PROJECT_NAME}
${SRCS}
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/flash_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/msc_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-gpio/ports/rp2040/gpio.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-i2c/ports/rp2040/i2c.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-spi/ports/rp2040/spi.c
Expand All @@ -59,7 +62,7 @@ set(RBC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/bin/picorbc)

# Ruby

if(PRK_NO_MSC)
if(PICORUBY_NO_MSC)
add_custom_target(keymap
COMMAND ${RBC} -Bkeymap -o ./keymap.c ../keymap.rb
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
Expand Down Expand Up @@ -96,7 +99,7 @@ add_dependencies(${PROJECT_NAME}
${RUBY_TASK_FILES}
)

if(PRK_NO_MSC)
if(PICORUBY_NO_MSC)
add_dependencies(${PROJECT_NAME}
keymap
)
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
concurrent-ruby (1.2.0)
concurrent-ruby (1.2.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
minitest (5.17.0)
mrubyc-test (0.9.1)
minitest (5.18.0)
mrubyc-test (0.9.2)
activesupport (~> 7.0)
rufo (~> 0.12)
thor (~> 1.2)
rake (13.0.6)
rufo (0.14.0)
rufo (0.15.1)
thor (1.2.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
task :libmruby_no_msc => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "CFLAGS='-DPRK_NO_MSC=1' MRUBY_CONFIG=#{MRUBY_CONFIG} rake"
sh "CFLAGS='-DPICORUBY_NO_MSC=1' MRUBY_CONFIG=#{MRUBY_CONFIG} rake"
end
end

Expand Down Expand Up @@ -81,8 +81,8 @@ task :build_with_keymap, ['keyboard_name'] => [:libmruby_no_msc, :test] do |_t,
end
dir = "keyboards/#{args.keyboard_name}"
FileUtils.mkdir_p "#{dir}/build"
#sh "cmake -DPRK_NO_MSC=1 -DCMAKE_BUILD_TYPE=Debug -B #{dir}/build"
sh "#{mruby_config} cmake -DPRK_NO_MSC=1 -B #{dir}/build"
#sh "cmake -DPICORUBY_NO_MSC=1 -DCMAKE_BUILD_TYPE=Debug -B #{dir}/build"
sh "#{mruby_config} cmake -DPICORUBY_NO_MSC=1 -B #{dir}/build"
sh "cmake --build #{dir}/build"
end

Expand All @@ -100,7 +100,7 @@ task :test => %i(mrubyc_test)

desc "run unit test for ruby program"
task :mrubyc_test => :setup_test do
sh %q(CFLAGS=-DMAX_SYMBOLS_COUNT=1000 MRUBYCFILE=test/Mrubycfile bundle exec mrubyc-test)
sh %q(MRUBYCFILE=test/Mrubycfile bundle exec mrubyc-test)
end

task :setup_test do
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Keyboard_init_sub(mrbc_class *mrbc_class_Keyboard)
mrbc_define_method(0, mrbc_class_Keyboard, "uart_anchor", c_Keyboard_uart_anchor);
mrbc_define_method(0, mrbc_class_Keyboard, "autoreload_ready?", c_autoreload_ready_q);
mrbc_define_method(0, mrbc_class_Keyboard, "autoreload_off", c_autoreload_off);
#ifdef PRK_NO_MSC
#ifdef PICORUBY_NO_MSC
autoreload_state = AUTORELOAD_NONE;
#else
autoreload_state = AUTORELOAD_READY;
Expand Down
19 changes: 13 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* tasks */
#include "../build/mrb/usb_task.c"

#ifdef PRK_NO_MSC
#ifdef PICORUBY_NO_MSC
#include <keymap.c>
#endif

Expand All @@ -41,22 +41,29 @@ int loglevel = LOGLEVEL_WARN;

int autoreload_state; /* from keyboard.h */

#ifndef PRK_NO_MSC
#ifndef PICORUBY_NO_MSC

#ifndef NODE_BOX_SIZE
#define NODE_BOX_SIZE 50
#endif

#endif /* PRK_NO_MSC */
void
tud_msc_write10_complete_cb(uint8_t lun)
{
(void)lun;
autoreload_state = AUTORELOAD_READY;
}

#endif /* PICORUBY_NO_MSC */

static void
prk_init_picoruby(void)
{
/* CONST */
mrbc_sym sym_id = mrbc_str_to_symid("SIZEOF_POINTER");
mrbc_set_const(sym_id, &mrbc_integer_value(PICORBC_PTR_SIZE));
sym_id = mrbc_str_to_symid("PRK_NO_MSC");
#ifdef PRK_NO_MSC
sym_id = mrbc_str_to_symid("PICORUBY_NO_MSC");
#ifdef PICORUBY_NO_MSC
mrbc_set_const(sym_id, &mrbc_true_value());
#else
mrbc_set_const(sym_id, &mrbc_false_value());
Expand Down Expand Up @@ -87,7 +94,7 @@ main(void)
tusb_init();
/* Tasks */
mrbc_create_task(usb_task, 0);
#ifdef PRK_NO_MSC
#ifdef PICORUBY_NO_MSC
mrbc_create_task(keymap, 0);
#endif
mrbc_run();
Expand Down
6 changes: 3 additions & 3 deletions src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tud_descriptor_device_cb(void)
// Configuration Descriptor
//--------------------------------------------------------------------+

#ifdef PRK_NO_MSC
#ifdef PICORUBY_NO_MSC
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN)
#else
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN)
Expand Down Expand Up @@ -131,7 +131,7 @@ enum
ITF_NUM_CDC_DATA,
ITF_NUM_HID,
ITF_NUM_JOYSTICK,
#ifndef PRK_NO_MSC
#ifndef PICORUBY_NO_MSC
ITF_NUM_MSC,
#endif
ITF_NUM_TOTAL
Expand All @@ -145,7 +145,7 @@ uint8_t const desc_fs_configuration[] =
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),

#ifndef PRK_NO_MSC
#ifndef PICORUBY_NO_MSC
// Interface number, string index, EP Out & EP In address, EP size
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
#endif
Expand Down
17 changes: 17 additions & 0 deletions test/models/gpio_c.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class GPIO
IN = 0b000001
OUT = 0b000010
HIGH_Z = 0b000100
PULL_UP = 0b001000
PULL_DOWN = 0b010000
OPEN_DRAIN = 0b100000
def self._init(pin)
end
def self.set_dir_at(pin,flag)
end
def self.pull_up_at(pin)
end
def self.open_drain_at(pin)
end
end

4 changes: 1 addition & 3 deletions test/tests/keyboard_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class KeyboardTest < MrubycTestCase
# TODO: improve mock functionality of mrubyc-test
def define_mocks
kbd = Keyboard.new
mock(kbd).gpio_init(1)
mock(kbd).gpio_set_dir(2)
# mock(GPIO)._init(1)
end
def setup
@kbd = Keyboard.new
Expand Down

0 comments on commit b9d0c7a

Please sign in to comment.