DeepBlueRobotics / test-board

The code for our new test board
0 stars 0 forks source link

SolenoidSubsystem.close() can't set solenoid state kReverse if it starts in kOff #3

Open brettle opened 5 years ago

brettle commented 5 years ago

Create a unit test first to confirm that this is a bug and then fix it.

kevinzwang commented 5 years ago

I tried creating a test, but I believe that it is not possible to actually test wpilib functionality without physical parts. Here is my output for ./gradlew test:


> Configure project :
NOTE: You are using an ALPHA version of GradleRIO, designed for the 2019 Season!
This release uses the 2018 Core Libraries, however all tooling (GradleRIO + IDE support) is incubating for 2019
If you encounter any issues and/or bugs, please report them to https://github.com/wpilibsuite/GradleRIO

> Task :compileTestJava
Note: /Users/kevin/dev/test-board/src/test/java/frc/robot/ExampleTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by worker.org.gradle.internal.reflect.JavaMethod (file:/Users/kevin/.gradle/caches/4.9/workerMain/gradle-worker.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of worker.org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

frc.robot.ExampleTest > mockitoTest() PASSED

frc.robot.ExampleTest > junitTest() PASSED
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fff6904b11b, pid=33965, tid=41219
#
# JRE version: Java(TM) SE Runtime Environment (9.0+11) (build 9.0.4+11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (9.0.4+11, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# C  [libsystem_pthread.dylib+0x111b]  pthread_mutex_lock+0x0
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/kevin/dev/test-board/hs_err_pid33965.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

frc.robot.TestSolenoids > testClose() SKIPPED

> Task :test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Process 'Gradle Test Executor 2' finished with non-zero exit value 134
  This problem might be caused by incorrect test process configuration.
  Please refer to the test execution section in the user guide at https://docs.gradle.org/4.9/userguide/java_plugin.html#sec:test_execution

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
4 actionable tasks: 3 executed, 1 up-to-date
kevinzwang commented 5 years ago

here is my code:

package frc.robot;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import frc.robot.subsystems.SolenoidSubsystem;

public class TestSolenoids {
    @Test
    public void testClose() {
        DoubleSolenoid solenoid = new DoubleSolenoid(0, 1);
        DoubleSolenoid spy = spy(solenoid);
        spy.set(DoubleSolenoid.Value.kOff);

        ArrayList<DoubleSolenoid> solenoids = new ArrayList<DoubleSolenoid>();
        solenoids.add(solenoid);

        SolenoidSubsystem solSub = new SolenoidSubsystem(solenoids);
        solSub.close(0);
        assertEquals(spy.get(), DoubleSolenoid.Value.kOff);
    }
}