Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Check ROM size #124

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/features/bugs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Feature: Fixing issues
"""
When I build test.asm
And file test.rom exists
And file test.rom size is 48k
Then page 0 has no cartridge header
And page 1 has cartridge header
And sym contains INIT
Expand All @@ -31,6 +32,7 @@ Feature: Fixing issues
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 512k

Given I write the code to test.asm
"""
Expand Down
32 changes: 32 additions & 0 deletions test/features/program.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,35 @@ Feature: Test program functions
When I build test.asm
Then text file contains Hello ASMSX
And text file does not contain unknown assembler

# START and ROM directives have different behaviours
# depending if you put them after or before PAGE 1
Scenario: Expected ROM file size (#121) - 8k
Given I write the code to test.asm
"""
ZILOG
BIOS
PAGE 1
START MAIN
ROM
MAIN:
ld A,1
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 8k

Scenario: Expected ROM file size (#121) - 24k
Given I write the code to test.asm
"""
ZILOG
BIOS
START MAIN
ROM
PAGE 1
MAIN:
ld A,1
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 24k
18 changes: 18 additions & 0 deletions test/steps/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ def step_impl(context, folder):
def step_impl(context, file):
assert os.path.isfile(file), f"File {file} does not exist"

def human_size_to_int(size: str) -> int:
size = size.lower()
if size[-1] == 'k':
return int(size[:-1]) * 1024
elif size[-1] == 'm':
return int(size[:-1]) * 1024 * 1024
elif size.isnumeric():
return int(size)
else:
raise("Value not valid")

@step('file {file} size is {size}')
@step('file size of {file} is {size}')
def step_impl(context, file, size: str):
expected_size = human_size_to_int(size)
file_size = os.path.getsize(file)
assert file_size == expected_size, f"File {file} has size {file_size} (expected {expected_size})"

@given('I write to {file}')
@given('I write the code to {file}')
def step_impl(context, file):
Expand Down
Loading