Skip to content

Commit 4d9b0c4

Browse files
committed
Tim's refactor of track0 sectors for os9 format
This simplifies how the sectorsTrack0 variable is used, giving it an "unset" value of 0. It moves a test that forks the "os9 format" command into a new file unittest/os9commandtest.c Fixes the order of libraries, as needed in automated testing. This PR was originally #31 but the fundamental bug fix was made in #29 so it has been adapted.
1 parent 0767896 commit 4d9b0c4

File tree

4 files changed

+65
-42
lines changed

4 files changed

+65
-42
lines changed

build/unix/unittest/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ include ../rules.mak
44
vpath %.c ../../../unittest
55

66
LDLIBS += -L../libtoolshed -L../libcoco -L../libcecb -L../libdecb \
7-
-L../librbf -L../libmisc -L../libnative -L../libsys \
8-
-ltoolshed -lcoco -lcecb -ldecb -lrbf -lmisc -lnative -lsys -lm
7+
-L../librbf -L../libnative -L../libmisc -L../libsys \
8+
-ltoolshed -lcoco -lcecb -ldecb -lrbf -lnative -lmisc -lsys -lm
99

10-
TESTS = librbftest libdecbtest libcecbtest libtoolshedtest
10+
TESTS = librbftest libdecbtest libcecbtest libtoolshedtest os9commandtest
1111

1212
testall: $(TESTS)
1313
ifeq (,$(NOTEST))
1414
./librbftest
1515
./libdecbtest
1616
./libcecbtest
1717
./libtoolshedtest
18+
./os9commandtest
1819
endif
1920

2021
clean:

os9/os9format.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ static char const *const helpMessage[] = {
3333
" -ss = single sided (default)\n",
3434
" -ds = double sided\n",
3535
" -tX = tracks (default = 35)\n",
36-
" -stX = sectors per track (default = 18)\n",
36+
" -stX = sectors per track (default = 18)\n",
3737
" -szX = sectors for track 0 (default = 18)\n",
3838
" -dr = format a Dragon disk\n",
3939
" Hard Drive Options:\n",
40-
" -lX = number of logical sectors\n",
40+
" -lX = number of logical sectors (floppy options ignored)\n",
4141
NULL
4242
};
4343

@@ -51,7 +51,7 @@ int os9format(int argc, char **argv)
5151
int tracks = 35;
5252
int heads = 1;
5353
int sectorsPerTrack = DEF_SECTORS_TRACK;
54-
int sectorsTrack0 = DEF_SECTORS_TRACK;
54+
int sectorsTrack0 = 0; /* mark as unset */
5555
int bytesPerSector = 256;
5656
int tpi = 48; /* 48 tpi */
5757
int density = 1; /* double density */
@@ -185,17 +185,12 @@ int os9format(int argc, char **argv)
185185

186186
case 't':
187187
sectorsPerTrack = atoi(p + 2);
188-
// Change sectors on track 0 only if it's not already been changed.
189-
if (DEF_SECTORS_TRACK == sectorsTrack0)
190-
{
191-
sectorsTrack0 = sectorsPerTrack;
192-
}
193188
break;
194-
189+
195190
case 'z':
196191
sectorsTrack0 = atoi(p + 2);
197192
break;
198-
193+
199194
default:
200195
fprintf(stderr,
201196
"%s: unknown option '%c'\n",
@@ -245,6 +240,12 @@ int os9format(int argc, char **argv)
245240
}
246241
}
247242

243+
/* match sectors on track 0 only if it's unset. */
244+
if (sectorsTrack0 == 0)
245+
{
246+
sectorsTrack0 = sectorsPerTrack;
247+
}
248+
248249
/* if logicalSectors != 0, then format as a hard drive image */
249250
if (logicalSectors != 0)
250251
{
@@ -270,12 +271,11 @@ int os9format(int argc, char **argv)
270271
if (logicalSectors % i == 0)
271272
{
272273
sectorsPerTrack = logicalSectors / i;
274+
sectorsTrack0 = sectorsPerTrack;
273275
heads = i;
274276
i = 0;
275277
}
276278
}
277-
278-
sectorsTrack0 = sectorsPerTrack;
279279
}
280280

281281
/* walk command line for pathnames */
@@ -291,7 +291,7 @@ int os9format(int argc, char **argv)
291291

292292
error_code ec =
293293
_os9_format(argv[i], os968k, tracks,
294-
sectorsPerTrack,sectorsTrack0,
294+
sectorsPerTrack, sectorsTrack0,
295295
heads, bytesPerSector, &clusterSize,
296296
diskName, sectorAllocationSize,
297297
tpi, density, formatEntire,

unittest/librbftest.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ void test_os9_format()
3535
// (gdb) b _os9_format
3636
// (gdb) run format test.dsk -l65000
3737
// Breakpoint 1, _os9_format (pathname=0x7fffffffe0ad "test.dsk", os968k=0,
38-
// tracks=125, sectorsPerTrack=4, sectorsTrack0=4, heads=130, sectorSize=256,
38+
// tracks=125, sectorsPerTrack=4, sectorsTrack0=4, heads=130, sectorSize=256,
3939
// clusterSize=0x7fffffffdae8, diskName=0x5555555761df "CoCo Disk",
40-
// sectorAllocationSize=8, tpi=0, density=0, formatEntire=0, isDragon=0, isHDD=1,
40+
// sectorAllocationSize=8, tpi=0, density=0, formatEntire=0, isDragon=0, isHDD=1,
4141
// totalSectors=0x7fffffffdaec, totalBytes=0x7fffffffdaf0) at ../../../librbf/librbfformat.c:25
4242
// (gdb) cont
4343
// Continuing.
@@ -54,6 +54,9 @@ void test_os9_format()
5454
// Size in bytes: 16640000
5555
// Cluster size: 1
5656

57+
// See test_os9_command_format for a test of the command line
58+
// that generates this scenario.
59+
5760
ec = _os9_format("test.dsk", /*68k=*/0,
5861
/*tracks=*/125, /*sPT=*/4, /*sT0=*/4, /*heads=*/130, /*sSize=*/256, &clusterSize,
5962
"HD-Test",
@@ -63,30 +66,6 @@ void test_os9_format()
6366
ASSERT_EQUALS(65000, totalSectors);
6467
ASSERT_EQUALS(65000 * 256, totalBytes);
6568

66-
#ifdef unix
67-
// In order to demonstrate the bug described in
68-
// https://github.com/nitros9project/toolshed/issues/28
69-
// we have to execute the `os9 format` command.
70-
// The bug is not in _os9_format, but in preparing its parameters.
71-
ec = system("rm -f test.dsk; ../os9/os9 format test.dsk -l65000");
72-
ASSERT_EQUALS(0, ec);
73-
// When `os9 format` was broken, it would succeed, but later
74-
// operations would fail, like `os9 makdir`:
75-
ec = _os9_makdir("test.dsk,/CMDS");
76-
ASSERT_EQUALS(0, ec);
77-
/*
78-
// ... But if `os9format` were in the tinytest linkage, this could work,
79-
// instead of using system():
80-
char* argv[] = {
81-
"os9", "format", "test.dsk", "-l65000", NULL
82-
};
83-
ec = os9format(4, argv);
84-
ASSERT_EQUALS(0, ec);
85-
ec = _os9_makdir("test.dsk,/CMDS");
86-
ASSERT_EQUALS(0, ec);
87-
*/
88-
#endif
89-
9069
// TODO: test format with oddball parameters to make sure it can survive
9170
}
9271

unittest/os9commandtest.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* ALWAYS BE TESTING!!!
3+
*
4+
* ALWAYS BE WRITING MORE TESTS!!!
5+
*
6+
* THIS WORK IS **NEVER** DONE!!!
7+
*/
8+
9+
#include "tinytest.h"
10+
#include <toolshed.h>
11+
12+
void test_os9_command_format()
13+
{
14+
error_code ec;
15+
native_path_id nativepath;
16+
u_int size;
17+
18+
ec = system("../os9/os9 format -e test.dsk -l65000 > /dev/null 2>&1");
19+
ASSERT_EQUALS(0, ec);
20+
21+
ec = _native_open(&nativepath, "test.dsk", FAM_READ);
22+
ASSERT_EQUALS(0, ec);
23+
24+
ec = _native_gs_size(nativepath, &size);
25+
ASSERT_EQUALS(0, ec);
26+
ASSERT_EQUALS(65000*256, size);
27+
28+
ec = _native_close(nativepath);
29+
ASSERT_EQUALS(0, ec);
30+
31+
ec = _os9_makdir("test.dsk,/CMDS");
32+
ASSERT_EQUALS(0, ec);
33+
}
34+
35+
int main()
36+
{
37+
remove("test.dsk");
38+
RUN(test_os9_command_format);
39+
40+
remove("test.dsk");
41+
42+
return TEST_REPORT();
43+
}

0 commit comments

Comments
 (0)