Skip to content

Testing.md

Trent M. Wyatt edited this page Apr 21, 2025 · 1 revision

Testing

Ready to ensure Bang is rock-solid for your Arduino’s command-line takeover? This page covers testing strategies to validate ! (shell), & (sketch uploads), and @ (macro) commands, making sure BANG("echo Hello"), BANG("&blink\n"), and BANG("@play") work flawlessly. With Bang’s lean design for Arduino’s tight memory, these tests keep your project bulletproof. Let’s hammer those bugs and make your microcontroller unstoppable!

Overview

  • Purpose: Verify Bang’s functionality across Arduino and host.
  • Key Areas:
    • Serial-USB communication.
    • Shell command execution (!).
    • Sketch uploads (&).
    • Dynamic macro management (@add_macro, @play, @delete_macro).
  • Tools: Arduino IDE, Serial Monitor, arduino_exec.py, example sketches.

Testing Strategies

1. Serial Communication

  • Goal: Confirm Arduino-host Serial-USB connection.
  • Test:
    • Upload a simple sketch:

      #include <Bang.h>
      Bang bang(Serial);
      
      void setup() {
          Serial.begin(38400);
          while (!Serial) ;
      }
      
      void loop() {
          BANG("echo Test Serial");
          delay(1000);
      }
    • Run arduino_exec.py:

      sudo python3 arduino_exec.py -p /dev/cu.usbserial-00100 -b 38400
    • Open Serial Monitor (Arduino IDE, 38400 baud).

  • Expected Result: Serial Monitor shows Test Serial every second.
  • Fixes: Check baud rate, port, or arduino_exec.py status (see Troubleshooting).

2. Shell Commands (!)

  • Goal: Verify ! commands execute correctly on the host.
  • Test:
    • Use cmd.ino from examples/ or this sketch:

      #include <Bang.h>
      Bang bang(Serial);
      
      void setup() {
          Serial.begin(38400);
          while (!Serial) ;
      }
      
      void loop() {
          BANG("echo Hello World");
          delay(1000);
          BANG("date");
          delay(1000);
      }
    • Run arduino_exec.py (as above).

    • Open Serial Monitor.

  • Expected Result: Serial Monitor shows Hello World, current date.
  • Fixes: Verify command syntax, host shell compatibility.

3. Dynamic Macros (@)

  • Goal: Test macro definition, invocation, listing, and deletion.
  • Test:
    • Upload a macro test sketch:

      #include <Bang.h>
      Bang bang(Serial);
      
      void setup() {
          Serial.begin(38400);
          while (!Serial) ;
      }
      
      void loop() {
          BANG("@add_macro:play:osascript -e 'tell application \"Music\" to play'");
          delay(1000);
          BANG("@play");
          delay(5000);
          BANG("@list_macros");
          delay(1000);
          BANG("@delete_macro:play");
          delay(1000);
          BANG("@list_macros");
          delay(5000);
      }
    • Run arduino_exec.py (as above).

    • Open Serial Monitor.

  • Expected Result:
    • Music plays (macOS).
    • Serial Monitor shows Macro 'play' created, macro list with play, then empty list after deletion.
  • Fixes: Check macro syntax, sudo for arduino_exec.py (see Python Agent).

4. Sketch Uploads (&)

  • Goal: Confirm &sketch_name\n uploads new sketches.
  • Test:
    • Use upload.ino from examples/:

      #include <Bang.h>
      Bang bang(Serial);
      
      void setup() {
          Serial.begin(38400);
          while (!Serial) ;
      }
      
      void loop() {
          BANG("&blink\n"); // Uploads blink.ino
          delay(10000);
      }
    • Place blink.ino in arduino_exec.py’s directory.

    • Run arduino_exec.py (as above).

    • Open Serial Monitor.

  • Expected Result: Arduino restarts, Serial Monitor shows blink.ino output (e.g., Blink Example).
  • Fixes: Verify arduino-cli, sketch path, sudo (see Dynamic Uploading).

Automated Testing

  • Arduino Side:
    • Create a test sketch to cycle through commands:

      #include <Bang.h>
      Bang bang(Serial);
      
      void setup() {
          Serial.begin(38400);
          while (!Serial) ;
          Serial.println("Test Start");
          BANG("echo Test Shell");
          BANG("@add_macro:test:echo Macro Test");
          BANG("@test");
          BANG("@list_macros");
          BANG("@delete_macro:test");
          BANG("&blink\n");
      }
      
      void loop() {}
    • Check Serial Monitor for expected outputs.

  • Host Side:
    • Add logging to arduino_exec.py:

      print(f"Test: {command}, Result: {result}")
    • Run tests and verify logs.

Troubleshooting

  • Test Fails: Check Serial Monitor logs, ensure arduino_exec.py runs with sudo.
  • Macro Errors: Use BANG("@list_macros") to debug.
  • Upload Issues: Test arduino-cli manually (see Troubleshooting).
  • Memory Limits: Simplify test sketches to fit Arduino’s RAM.

Next Steps


Back to Home | Next: Contributing

Clone this wiki locally