diff options
Diffstat (limited to '')
| -rw-r--r-- | src/peripherals/adc.spec.ts | 7 | ||||
| -rw-r--r-- | src/peripherals/clock.spec.ts | 1 | ||||
| -rw-r--r-- | src/peripherals/eeprom.spec.ts | 3 | ||||
| -rw-r--r-- | src/peripherals/gpio.spec.ts | 17 | ||||
| -rw-r--r-- | src/peripherals/spi.spec.ts | 7 | ||||
| -rw-r--r-- | src/peripherals/timer.spec.ts | 27 | ||||
| -rw-r--r-- | src/peripherals/twi.spec.ts | 27 | ||||
| -rw-r--r-- | src/peripherals/usart.spec.ts | 19 | ||||
| -rw-r--r-- | src/peripherals/watchdog.spec.ts | 1 |
9 files changed, 59 insertions, 50 deletions
diff --git a/src/peripherals/adc.spec.ts b/src/peripherals/adc.spec.ts index 4eb9aff..c67b615 100644 --- a/src/peripherals/adc.spec.ts +++ b/src/peripherals/adc.spec.ts @@ -1,6 +1,7 @@ +import { describe, expect, it, vi } from 'vitest'; import { CPU } from '../cpu/cpu'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; -import { AVRADC, adcConfig, ADCMuxInputType } from './adc'; +import { adcConfig, ADCMuxInputType, AVRADC } from './adc'; const R16 = 16; const R17 = 17; @@ -51,7 +52,7 @@ describe('ADC', () => { const adc = new AVRADC(cpu, adcConfig); const runner = new TestProgramRunner(cpu); - const adcReadSpy = jest.spyOn(adc, 'onADCRead'); + const adcReadSpy = vi.spyOn(adc, 'onADCRead'); adc.channelValues[0] = 2.56; // should result in 2.56/5*1024 = 524 // Setup @@ -114,7 +115,7 @@ describe('ADC', () => { /* do nothing on break */ }); - const adcReadSpy = jest.spyOn(adc, 'onADCRead'); + const adcReadSpy = vi.spyOn(adc, 'onADCRead'); adc.channelValues[0] = 2.56; // should result in 2.56/5*1024 = 524 // Setup diff --git a/src/peripherals/clock.spec.ts b/src/peripherals/clock.spec.ts index 69fc832..cb45a14 100644 --- a/src/peripherals/clock.spec.ts +++ b/src/peripherals/clock.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { CPU } from '../cpu/cpu'; import { AVRClock, clockConfig } from './clock'; diff --git a/src/peripherals/eeprom.spec.ts b/src/peripherals/eeprom.spec.ts index a90116f..a9cab9b 100644 --- a/src/peripherals/eeprom.spec.ts +++ b/src/peripherals/eeprom.spec.ts @@ -1,6 +1,7 @@ +import { describe, expect, it } from 'vitest'; import { CPU } from '../cpu/cpu'; -import { AVREEPROM, EEPROMMemoryBackend } from './eeprom'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; +import { AVREEPROM, EEPROMMemoryBackend } from './eeprom'; // EEPROM Registers const EECR = 0x3f; diff --git a/src/peripherals/gpio.spec.ts b/src/peripherals/gpio.spec.ts index 755476e..046f196 100644 --- a/src/peripherals/gpio.spec.ts +++ b/src/peripherals/gpio.spec.ts @@ -1,6 +1,7 @@ import { CPU } from '../cpu/cpu'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; import { AVRIOPort, portBConfig, PinState, portDConfig, PinOverrideMode } from './gpio'; +import { describe, it, expect, vi } from 'vitest'; // CPU registers const SREG = 95; @@ -41,7 +42,7 @@ describe('GPIO', () => { it('should invoke the listeners when the port is written to', () => { const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(); + const listener = vi.fn(); cpu.writeData(DDRB, 0x0f); port.addListener(listener); cpu.writeData(PORTB, 0x55); @@ -52,7 +53,7 @@ describe('GPIO', () => { it('should invoke the listeners when DDR changes (issue #28)', () => { const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(); + const listener = vi.fn(); cpu.writeData(PORTB, 0x55); port.addListener(listener); cpu.writeData(DDRB, 0xf0); @@ -62,7 +63,7 @@ describe('GPIO', () => { it('should invoke the listeners when pullup register enabled (issue #62)', () => { const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(); + const listener = vi.fn(); port.addListener(listener); cpu.writeData(PORTB, 0x55); expect(listener).toHaveBeenCalledWith(0x55, 0); @@ -71,7 +72,7 @@ describe('GPIO', () => { it('should toggle the pin when writing to the PIN register', () => { const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(); + const listener = vi.fn(); port.addListener(listener); cpu.writeData(DDRB, 0x0f); cpu.writeData(PORTB, 0x55); @@ -101,7 +102,7 @@ describe('GPIO', () => { const portD = new AVRIOPort(cpu, portDConfig); const runner = new TestProgramRunner(cpu); - const listener = jest.fn(); + const listener = vi.fn(); portD.addListener(listener); // Setup: pins 6, 3 are output, set to HIGH @@ -132,7 +133,7 @@ describe('GPIO', () => { it('should remove the given listener', () => { const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(); + const listener = vi.fn(); port.addListener(listener); cpu.writeData(DDRB, 0x0f); port.removeListener(listener); @@ -176,7 +177,7 @@ describe('GPIO', () => { // Related issue: https://github.com/wokwi/avr8js/issues/9 const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(() => { + const listener = vi.fn(() => { expect(port.pinState(PB0)).toBe(PinState.High); }); expect(port.pinState(PB0)).toBe(PinState.Input); @@ -190,7 +191,7 @@ describe('GPIO', () => { // Related issue: https://github.com/wokwi/avr8js/issues/47 const cpu = new CPU(new Uint16Array(1024)); const port = new AVRIOPort(cpu, portBConfig); - const listener = jest.fn(() => { + const listener = vi.fn(() => { expect(port.pinState(PB0)).toBe(PinState.Low); }); expect(port.pinState(PB0)).toBe(PinState.Input); diff --git a/src/peripherals/spi.spec.ts b/src/peripherals/spi.spec.ts index da429fe..72884c5 100644 --- a/src/peripherals/spi.spec.ts +++ b/src/peripherals/spi.spec.ts @@ -1,6 +1,7 @@ +import { describe, expect, it, vi } from 'vitest'; import { CPU } from '../cpu/cpu'; -import { AVRSPI, spiConfig } from './spi'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; +import { AVRSPI, spiConfig } from './spi'; const FREQ_16MHZ = 16e6; @@ -99,7 +100,7 @@ describe('SPI', () => { it('should call the `onByteTransfer` callback when initiating an SPI trasfer by writing to SPDR', () => { const cpu = new CPU(new Uint16Array(1024)); const spi = new AVRSPI(cpu, spiConfig, FREQ_16MHZ); - spi.onByte = jest.fn(); + spi.onByte = vi.fn(); cpu.writeData(SPCR, SPE | MSTR); cpu.writeData(SPDR, 0x8f); @@ -110,7 +111,7 @@ describe('SPI', () => { it('should ignore SPDR writes when the SPE bit in SPCR is clear', () => { const cpu = new CPU(new Uint16Array(1024)); const spi = new AVRSPI(cpu, spiConfig, FREQ_16MHZ); - spi.onByte = jest.fn(); + spi.onByte = vi.fn(); cpu.writeData(SPCR, MSTR); cpu.writeData(SPDR, 0x8f); diff --git a/src/peripherals/timer.spec.ts b/src/peripherals/timer.spec.ts index 609908d..893fe32 100644 --- a/src/peripherals/timer.spec.ts +++ b/src/peripherals/timer.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, vi } from 'vitest'; import { CPU } from '../cpu/cpu'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; import { AVRIOPort, PinOverrideMode, portBConfig, portDConfig } from './gpio'; @@ -544,7 +545,7 @@ describe('timer', () => { // Listen to Port B's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); cpu.writeData(TCCR0B, FOC0B); @@ -580,7 +581,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); @@ -633,7 +634,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); @@ -679,7 +680,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); @@ -753,7 +754,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const nopCount = lines.filter((line) => line.bytes == nopOpCode).length; const runner = new TestProgramRunner(cpu); @@ -800,7 +801,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); @@ -833,7 +834,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); runner.runInstructions(instructionCount); @@ -861,7 +862,7 @@ describe('timer', () => { // Listen to Port D's internal callback const portD = new AVRIOPort(cpu, portDConfig); - const gpioCallback = jest.spyOn(portD, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portD, 'timerOverridePin'); const runner = new TestProgramRunner(cpu); runner.runInstructions(instructionCount); @@ -921,7 +922,7 @@ describe('timer', () => { IN r17, 0x26 ; R17 = TCNT; // TCNT0 should read 0x0 IN r18, 0x26 ; R18 = TCNT; // TCNT0 should read 0x0 - LDI r16, 0x2 ; OCR0A = 0x2; // TCNT0 should read 0x0 + LDI r16, 0x2 ; OCR0A = 0x2; // TCNT0 should read 0x1 OUT 0x27, r16 ; // TCNT0 should read 0x1 NOP ; // TCNT0 should read 0x2 IN r19, 0x26 ; R19 = TCNT; // TCNT0 should read 0x1 @@ -1118,7 +1119,7 @@ describe('timer', () => { // Listen to Port B's internal callback const portB = new AVRIOPort(cpu, portBConfig); - const gpioCallback = jest.spyOn(portB, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portB, 'timerOverridePin'); const nopCount = lines.filter((line) => line.bytes == nopOpCode).length; const runner = new TestProgramRunner(cpu); @@ -1164,7 +1165,7 @@ describe('timer', () => { // Listen to Port B's internal callback const portB = new AVRIOPort(cpu, portBConfig); - const gpioCallback = jest.spyOn(portB, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portB, 'timerOverridePin'); const nopCount = lines.filter((line) => line.bytes == nopOpCode).length; const runner = new TestProgramRunner(cpu); @@ -1192,7 +1193,7 @@ describe('timer', () => { // Listen to Port B's internal callback const portB = new AVRIOPort(cpu, portBConfig); - const gpioCallback = jest.spyOn(portB, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portB, 'timerOverridePin'); cpu.writeData(TCCR1C, FOC1C); @@ -1212,7 +1213,7 @@ describe('timer', () => { // Listen to Port B's internal callback const portB = new AVRIOPort(cpu, portBConfig); - const gpioCallback = jest.spyOn(portB, 'timerOverridePin'); + const gpioCallback = vi.spyOn(portB, 'timerOverridePin'); cpu.writeData(TCCR1C, FOC1C); diff --git a/src/peripherals/twi.spec.ts b/src/peripherals/twi.spec.ts index 342d611..5ddace5 100644 --- a/src/peripherals/twi.spec.ts +++ b/src/peripherals/twi.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, vi } from 'vitest'; import { CPU } from '../cpu/cpu'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; import { AVRTWI, twiConfig } from './twi'; @@ -61,7 +62,7 @@ describe('TWI', () => { it('should call the startEvent handler when TWSTA bit is written 1', () => { const cpu = new CPU(new Uint16Array(1024)); const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); - jest.spyOn(twi.eventHandler, 'start'); + vi.spyOn(twi.eventHandler, 'start'); cpu.writeData(TWCR, TWINT | TWSTA | TWEN); cpu.cycles++; cpu.tick(); @@ -78,14 +79,14 @@ describe('TWI', () => { cpu.tick(); // Repeated start - jest.spyOn(twi.eventHandler, 'start'); + vi.spyOn(twi.eventHandler, 'start'); cpu.writeData(TWCR, TWINT | TWSTA | TWEN); cpu.cycles++; cpu.tick(); expect(twi.eventHandler.start).toHaveBeenCalledWith(true); // Now try to connect... - jest.spyOn(twi.eventHandler, 'connectToSlave'); + vi.spyOn(twi.eventHandler, 'connectToSlave'); cpu.writeData(TWDR, 0x80); // Address 0x40, write mode cpu.writeData(TWCR, TWINT | TWEN); cpu.cycles++; @@ -199,11 +200,11 @@ describe('TWI', () => { const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); const runner = new TestProgramRunner(cpu, onTestBreak); twi.eventHandler = { - start: jest.fn(), - stop: jest.fn(), - connectToSlave: jest.fn(), - writeByte: jest.fn(), - readByte: jest.fn(), + start: vi.fn(), + stop: vi.fn(), + connectToSlave: vi.fn(), + writeByte: vi.fn(), + readByte: vi.fn(), }; // Step 1: wait for start condition @@ -368,11 +369,11 @@ describe('TWI', () => { const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); const runner = new TestProgramRunner(cpu, onTestBreak); twi.eventHandler = { - start: jest.fn(), - stop: jest.fn(), - connectToSlave: jest.fn(), - writeByte: jest.fn(), - readByte: jest.fn(), + start: vi.fn(), + stop: vi.fn(), + connectToSlave: vi.fn(), + writeByte: vi.fn(), + readByte: vi.fn(), }; // Step 1: wait for start condition diff --git a/src/peripherals/usart.spec.ts b/src/peripherals/usart.spec.ts index 8dbd5ce..fcbeec1 100644 --- a/src/peripherals/usart.spec.ts +++ b/src/peripherals/usart.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, vi } from 'vitest'; import { CPU } from '../cpu/cpu'; import { AVRUSART, usart0Config } from './usart'; @@ -56,7 +57,7 @@ describe('USART', () => { it('should call onConfigurationChange when the baudRate changes', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - const onConfigurationChange = jest.fn(); + const onConfigurationChange = vi.fn(); usart.onConfigurationChange = onConfigurationChange; cpu.writeData(UBRR0H, 0); @@ -111,7 +112,7 @@ describe('USART', () => { it('should call onConfigurationChange when bitsPerChar change', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - const onConfigurationChange = jest.fn(); + const onConfigurationChange = vi.fn(); usart.onConfigurationChange = onConfigurationChange; cpu.writeData(UCSR0C, UCSZ0 | UCSZ1); @@ -175,7 +176,7 @@ describe('USART', () => { it('should invoke onByteTransmit when UDR0 is written to', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onByteTransmit = jest.fn(); + usart.onByteTransmit = vi.fn(); cpu.writeData(UCSR0B, TXEN); cpu.writeData(UDR0, 0x61); expect(usart.onByteTransmit).toHaveBeenCalledWith(0x61); @@ -185,7 +186,7 @@ describe('USART', () => { it('txEnable should equal true when the transitter is enabled', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onByteTransmit = jest.fn(); + usart.onByteTransmit = vi.fn(); expect(usart.txEnable).toEqual(false); cpu.writeData(UCSR0B, TXEN); expect(usart.txEnable).toEqual(true); @@ -194,7 +195,7 @@ describe('USART', () => { it('rxEnable should equal true when the transitter is enabled', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onByteTransmit = jest.fn(); + usart.onByteTransmit = vi.fn(); expect(usart.rxEnable).toEqual(false); cpu.writeData(UCSR0B, RXEN); expect(usart.rxEnable).toEqual(true); @@ -254,7 +255,7 @@ describe('USART', () => { it('should call onLineTransmit with the current line buffer after every newline', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onLineTransmit = jest.fn(); + usart.onLineTransmit = vi.fn(); cpu.writeData(UCSR0B, TXEN); cpu.writeData(UDR0, 0x48); // 'H' cpu.writeData(UDR0, 0x65); // 'e' @@ -268,7 +269,7 @@ describe('USART', () => { it('should not call onLineTransmit if no newline was received', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onLineTransmit = jest.fn(); + usart.onLineTransmit = vi.fn(); cpu.writeData(UCSR0B, TXEN); cpu.writeData(UDR0, 0x48); // 'H' cpu.writeData(UDR0, 0x69); // 'i' @@ -278,7 +279,7 @@ describe('USART', () => { it('should clear the line buffer after each call to onLineTransmit', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - usart.onLineTransmit = jest.fn(); + usart.onLineTransmit = vi.fn(); cpu.writeData(UCSR0B, TXEN); cpu.writeData(UDR0, 0x48); // 'H' cpu.writeData(UDR0, 0x69); // 'i' @@ -324,7 +325,7 @@ describe('USART', () => { it('should be ready to recieve the next byte after ~1.04ms when baudrate set to 9600', () => { const cpu = new CPU(new Uint16Array(1024)); const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); - const rxCompleteCallback = jest.fn(); + const rxCompleteCallback = vi.fn(); usart.onRxComplete = rxCompleteCallback; cpu.writeData(UCSR0B, RXEN); cpu.writeData(UBRR0L, 103); // baud: 9600 diff --git a/src/peripherals/watchdog.spec.ts b/src/peripherals/watchdog.spec.ts index edd7631..df72148 100644 --- a/src/peripherals/watchdog.spec.ts +++ b/src/peripherals/watchdog.spec.ts @@ -5,6 +5,7 @@ * Copyright (C) 2021 Uri Shaked */ +import { describe, expect, it } from 'vitest'; import { AVRClock, clockConfig } from '..'; import { CPU } from '../cpu/cpu'; import { asmProgram, TestProgramRunner } from '../utils/test-utils'; |
