TestFs.Mod 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. MODULE TestFs;
  2. IMPORT
  3. SYSTEM, Random, Files, Kernel, Commands, FoxBasic, Strings;
  4. TYPE
  5. Writer = OBJECT
  6. VAR
  7. id: LONGINT;
  8. file: Files.File;
  9. fw: Files.Writer;
  10. fileSize: HUGEINT;
  11. byteCount: HUGEINT;
  12. rndData, rndUpdate: Random.Generator;
  13. tStart: Kernel.MilliTimer;
  14. startByteCount: HUGEINT;
  15. fileName0: Files.FileName;
  16. partNum: LONGINT;
  17. partByteCount: LONGINT;
  18. run := FALSE, exited := FALSE: BOOLEAN;
  19. PROCEDURE &InitWriter(id: LONGINT; CONST fileName: ARRAY OF CHAR; fileSize: HUGEINT);
  20. BEGIN
  21. ASSERT(~exited);
  22. file := Files.New(fileName);
  23. ASSERT(file # NIL);
  24. Files.Register(file);
  25. Files.OpenWriter(fw,file,0);
  26. NEW(rndData);
  27. rndData.InitSeed(id);
  28. NEW(rndUpdate);
  29. rndUpdate.InitSeed(-id);
  30. SELF.id := id;
  31. SELF.fileSize := fileSize;
  32. COPY(fileName,fileName0);
  33. partNum := 0;
  34. byteCount := 0;
  35. partByteCount := 0;
  36. run := TRUE;
  37. END InitWriter;
  38. PROCEDURE Exit;
  39. BEGIN{EXCLUSIVE}
  40. run := FALSE;
  41. AWAIT(exited);
  42. END Exit;
  43. PROCEDURE Start;
  44. BEGIN {EXCLUSIVE}
  45. run := TRUE
  46. END Start;
  47. PROCEDURE Pause;
  48. BEGIN {EXCLUSIVE}
  49. run := FALSE
  50. END Pause;
  51. PROCEDURE Running (): BOOLEAN;
  52. BEGIN {EXCLUSIVE}
  53. RETURN run
  54. END Running;
  55. PROCEDURE Exited (): BOOLEAN;
  56. BEGIN {EXCLUSIVE}
  57. RETURN exited
  58. END Exited;
  59. PROCEDURE Loop;
  60. VAR
  61. v: LONGINT;
  62. strNum: ARRAY 16 OF CHAR;
  63. str: Files.FileName;
  64. t: LONGINT;
  65. BEGIN
  66. WHILE run & ((fileSize <= 0) OR (byteCount < fileSize)) & (fw.res = 0) DO
  67. v := rndData.Integer();
  68. fw.RawLInt(v);
  69. INC(byteCount,SIZEOF(LONGINT));
  70. INC(partByteCount,SIZEOF(LONGINT));
  71. IF partByteCount MOD 0x1000000 = 0 THEN
  72. Kernel.SetTimer(tStart,0);
  73. startByteCount := byteCount;
  74. END;
  75. (*
  76. IF rndUpdate.Dice(4096) = 0 THEN (* Files.DefaultWriterSize *)
  77. fw.Update;
  78. END;
  79. *)
  80. IF partByteCount = 0x40000000 THEN (* 1GB parts *)
  81. partByteCount := 0;
  82. INC(partNum);
  83. fw.Update;
  84. TRACE("closing file...");
  85. t := Kernel.GetTicks();
  86. file.Close;
  87. t := Kernel.GetTicks() - t;
  88. TRACE("closed file",t);
  89. Strings.IntToStr(partNum,strNum);
  90. Strings.Concat(fileName0,".p",str);
  91. Strings.Concat(str,strNum,str);
  92. TRACE("creating file...");
  93. t := Kernel.GetTicks();
  94. file := Files.New(str);
  95. t := Kernel.GetTicks() - t;
  96. TRACE("created file",t);
  97. TRACE("registering the created file...");
  98. t := Kernel.GetTicks();
  99. Files.Register(file);
  100. t := Kernel.GetTicks() - t;
  101. TRACE("registered the file",t);
  102. Files.OpenWriter(fw,file,0);
  103. TRACE("started a new file part",id,fileName0,partNum,byteCount);
  104. END;
  105. END;
  106. IF fw.res # 0 THEN
  107. TRACE("TestFs writer",id,"stopped due to a writer error",fw.res);
  108. END;
  109. fw.Update;
  110. run := FALSE;
  111. END Loop;
  112. BEGIN{ACTIVE}
  113. Kernel.SetTimer(tStart,0);
  114. startByteCount := 0;
  115. Loop;
  116. FINALLY
  117. BEGIN{EXCLUSIVE}
  118. exited := TRUE;
  119. END;
  120. END Writer;
  121. (* High-level reader activity *)
  122. Reader = OBJECT
  123. VAR
  124. id: LONGINT;
  125. file: Files.File;
  126. fr: Files.Reader;
  127. rndData: Random.Generator;
  128. byteCount: HUGEINT;
  129. run, exited: BOOLEAN;
  130. tStart: Kernel.MilliTimer;
  131. startByteCount: HUGEINT;
  132. fileName0: Files.FileName;
  133. partNum: LONGINT;
  134. partByteCount: LONGINT;
  135. PROCEDURE & InitReader(id: LONGINT; CONST fileName: ARRAY OF CHAR);
  136. BEGIN
  137. SELF.id := id;
  138. file := Files.Old(fileName);
  139. ASSERT(file # NIL);
  140. Files.OpenReader(fr, file, 0);
  141. NEW(rndData);
  142. rndData.InitSeed(id);
  143. COPY(fileName,fileName0);
  144. partNum := 0;
  145. byteCount := 0;
  146. partByteCount := 0;
  147. run := TRUE;
  148. END InitReader;
  149. PROCEDURE Exit;
  150. BEGIN {EXCLUSIVE}
  151. run := FALSE;
  152. AWAIT(exited);
  153. END Exit;
  154. PROCEDURE Start;
  155. BEGIN {EXCLUSIVE}
  156. run := TRUE
  157. END Start;
  158. PROCEDURE Pause;
  159. BEGIN {EXCLUSIVE}
  160. run := FALSE
  161. END Pause;
  162. PROCEDURE Running (): BOOLEAN;
  163. BEGIN {EXCLUSIVE}
  164. RETURN run
  165. END Running;
  166. PROCEDURE Exited (): BOOLEAN;
  167. BEGIN {EXCLUSIVE}
  168. RETURN exited
  169. END Exited;
  170. PROCEDURE Loop;
  171. VAR
  172. v: LONGINT;
  173. strNum: ARRAY 16 OF CHAR;
  174. str: Files.FileName;
  175. BEGIN
  176. WHILE run & (fr.res = 0) DO
  177. fr.RawLInt(v);
  178. INC(partByteCount, SIZEOF(LONGINT));
  179. INC(byteCount, SIZEOF(LONGINT));
  180. ASSERT(v = rndData.Integer());
  181. IF partByteCount MOD 0x1000000 = 0 THEN
  182. Kernel.SetTimer(tStart,0);
  183. startByteCount := byteCount;
  184. END;
  185. IF partByteCount = 0x40000000 THEN (* 1GB parts *)
  186. partByteCount := 0;
  187. INC(partNum);
  188. file.Close;
  189. Strings.IntToStr(partNum,strNum);
  190. Strings.Concat(fileName0,".p",str);
  191. Strings.Concat(str,strNum,str);
  192. file := Files.Old(str);
  193. IF file = NIL THEN
  194. RETURN;
  195. END;
  196. Files.OpenReader(fr,file,0);
  197. TRACE("started a new file part",id,fileName0,partNum,byteCount);
  198. END;
  199. END;
  200. END Loop;
  201. BEGIN {ACTIVE}
  202. Kernel.SetTimer(tStart, 0);
  203. startByteCount := 0;
  204. Loop;
  205. FINALLY
  206. BEGIN {EXCLUSIVE}
  207. exited := TRUE;
  208. END;
  209. END Reader;
  210. VAR
  211. writers: FoxBasic.List;
  212. readers: FoxBasic.List;
  213. (**
  214. Start id fileName fileSize ~
  215. *)
  216. PROCEDURE StartWriter*(ctx: Commands.Context);
  217. VAR
  218. id: LONGINT;
  219. fileName: Files.FileName;
  220. fileSize: LONGINT;
  221. w: Writer;
  222. i: LONGINT;
  223. BEGIN{EXCLUSIVE}
  224. IF ~ctx.arg.GetInteger(id,FALSE) THEN ctx.result := 1; RETURN; END;
  225. IF ~ctx.arg.GetString(fileName) THEN ctx.result := 1; RETURN;END;
  226. IF ~ctx.arg.GetInteger(fileSize,FALSE) THEN fileSize := -1; END;
  227. i := 0;
  228. WHILE (i < writers.Length()) & (writers.Get(i)(Writer).id # id) DO
  229. INC(i);
  230. END;
  231. IF i < writers.Length() THEN
  232. ctx.error.String("TestFs writer with ID "); ctx.error.Int(id,0); ctx.error.String(" already running"); ctx.error.Ln;
  233. ctx.result := 1;
  234. RETURN;
  235. END;
  236. NEW(w,id,fileName,fileSize);
  237. writers.Add(w);
  238. ctx.out.String("Started TestFs writer with ID "); ctx.out.Int(id,0);
  239. ctx.out.String(", fileName='"); ctx.out.String(fileName);
  240. ctx.out.String("', fileSize="); ctx.out.Int(fileSize,0); ctx.out.Ln;
  241. END StartWriter;
  242. (* ID *)
  243. PROCEDURE StopWriter*(ctx: Commands.Context);
  244. VAR
  245. id: LONGINT;
  246. i: LONGINT;
  247. BEGIN{EXCLUSIVE}
  248. IF ~ctx.arg.GetInteger(id,FALSE) THEN ctx.result := 1; RETURN; END;
  249. i := 0;
  250. WHILE (i < writers.Length()) & (writers.Get(i)(Writer).id # id) DO
  251. INC(i);
  252. END;
  253. IF i < writers.Length() THEN
  254. writers.Get(i)(Writer).Exit;
  255. writers.RemoveByIndex(i);
  256. ctx.out.String("Stopped TestFs writer with ID "); ctx.out.Int(id,0); ctx.out.Ln;
  257. ELSE
  258. ctx.error.String("TestFs writer with ID "); ctx.error.Int(id,0); ctx.error.String(" not found"); ctx.error.Ln;
  259. ctx.result := 1;
  260. RETURN;
  261. END;
  262. END StopWriter;
  263. PROCEDURE DoReportWriter(id: LONGINT; ctx: Commands.Context);
  264. VAR
  265. i: LONGINT;
  266. w: Writer;
  267. speed: REAL;
  268. BEGIN
  269. i := 0;
  270. WHILE (i < writers.Length()) & (writers.Get(i)(Writer).id # id) DO
  271. INC(i);
  272. END;
  273. IF i < writers.Length() THEN
  274. w := writers.Get(i)(Writer);
  275. speed := 1000.0 * REAL(w.byteCount-w.startByteCount) / Kernel.Elapsed(w.tStart);
  276. ctx.out.String("byte count="); ctx.out.Int(w.byteCount,0); ctx.out.Ln;
  277. ctx.out.String("speed="); ctx.out.FloatFix(speed,0,5,0); ctx.out.String(" bytes/s"); ctx.out.Ln;
  278. ctx.out.String("status: ");
  279. IF w.Exited() THEN
  280. ctx.out.String("Finished");
  281. ELSIF w.Running() THEN
  282. ctx.out.String("Running");
  283. ELSE
  284. ctx.out.String("Paused");
  285. END;
  286. ctx.out.Ln;
  287. ELSE
  288. ctx.error.String("TestFs writer with ID "); ctx.error.Int(id,0); ctx.error.String(" not found"); ctx.error.Ln;
  289. ctx.result := Commands.CommandError;
  290. END;
  291. END DoReportWriter;
  292. (**
  293. ReportWriter id ~
  294. *)
  295. PROCEDURE ReportWriter*(ctx: Commands.Context);
  296. VAR
  297. id: LONGINT;
  298. BEGIN{EXCLUSIVE}
  299. IF ~ctx.arg.GetInteger(id,FALSE) THEN
  300. ctx.result := Commands.CommandError;
  301. ctx.error.String("writer ID is not specified"); ctx.error.Ln;
  302. RETURN;
  303. END;
  304. DoReportWriter(id,ctx);
  305. END ReportWriter;
  306. PROCEDURE StartReader*(ctx: Commands.Context);
  307. VAR
  308. fileName: Files.FileName;
  309. r: Reader;
  310. id: LONGINT;
  311. i: LONGINT;
  312. BEGIN {EXCLUSIVE}
  313. IF ~ctx.arg.GetInteger(id,FALSE) THEN ctx.result := 1; RETURN; END;
  314. IF ~ctx.arg.GetString(fileName) THEN ctx.result := 1; RETURN;END;
  315. WHILE (i < readers.Length()) & (readers.Get(i)(Reader).id # id) DO INC(i); END;
  316. IF i < readers.Length() THEN
  317. ctx.error.String("TestFs reader with ID ");
  318. ctx.error.Int(id, 0);
  319. ctx.error.String(" already running.");
  320. ctx.error.Ln;
  321. ctx.result := 1;
  322. RETURN;
  323. END;
  324. NEW(r, id, fileName);
  325. readers.Add(r);
  326. ctx.out.String("Added TestFs reader with ID ");
  327. ctx.out.Int(id, 0);
  328. ctx.out.String(", fileName='");
  329. ctx.out.String(fileName);
  330. ctx.out.String("'");
  331. ctx.out.Ln;
  332. END StartReader;
  333. PROCEDURE StopReader*(ctx: Commands.Context);
  334. VAR
  335. r: Reader;
  336. id: LONGINT;
  337. i: LONGINT;
  338. BEGIN {EXCLUSIVE}
  339. IF ~ctx.arg.GetInteger(id, FALSE) THEN ctx.result := 1; RETURN; END;
  340. WHILE (i < readers.Length()) & (readers.Get(i)(Reader).id # id) DO INC(i); END;
  341. IF i = readers.Length() THEN
  342. ctx.error.String("TestFs reader with ID ");
  343. ctx.error.Int(id, 0);
  344. ctx.error.String(" is not running");
  345. ctx.error.Ln;
  346. ctx.result := 1;
  347. RETURN;
  348. END;
  349. r := readers.Get(i)(Reader);
  350. r.Exit;
  351. readers.RemoveByIndex(i);
  352. ctx.out.String("TestFs reader ");
  353. ctx.out.Int(id, 0);
  354. ctx.out.String(" stopped");
  355. ctx.out.Ln;
  356. END StopReader;
  357. PROCEDURE DoReportReader(id: LONGINT; ctx: Commands.Context);
  358. VAR
  359. r: Reader;
  360. i: LONGINT;
  361. speed: LONGREAL;
  362. BEGIN
  363. WHILE (i < readers.Length()) & (readers.Get(i)(Reader).id # id) DO INC(i); END;
  364. IF i < readers.Length() THEN
  365. r := readers.Get(i)(Reader);
  366. speed := 1000.0 * (r.byteCount-r.startByteCount) / Kernel.Elapsed(r.tStart);
  367. ctx.out.String("byte count="); ctx.out.Int(r.byteCount, 0); ctx.out.Ln;
  368. ctx.out.String("speed="); ctx.out.FloatFix(speed,0,5,0); ctx.out.String(" bytes/s"); ctx.out.Ln;
  369. ctx.out.String("status: ");
  370. IF r.Exited() THEN
  371. ctx.out.String("Finished");
  372. ELSIF r.Running() THEN
  373. ctx.out.String("Running");
  374. ELSE
  375. ctx.out.String("Paused");
  376. END;
  377. ctx.out.Ln;
  378. ELSE
  379. ctx.error.String("TestFs reader with ID "); ctx.error.Int(id,0); ctx.error.String(" not found"); ctx.error.Ln;
  380. ctx.result := Commands.CommandError;
  381. ctx.result := Commands.CommandError;
  382. RETURN;
  383. END;
  384. END DoReportReader;
  385. PROCEDURE ReportReader*(ctx: Commands.Context);
  386. VAR
  387. id: LONGINT;
  388. BEGIN {EXCLUSIVE}
  389. IF ~ctx.arg.GetInteger(id,FALSE) THEN
  390. ctx.result := Commands.CommandError;
  391. ctx.error.String("reader ID is not specified"); ctx.error.Ln;
  392. RETURN;
  393. END;
  394. DoReportReader(id,ctx);
  395. END ReportReader;
  396. PROCEDURE Report*(ctx: Commands.Context);
  397. VAR
  398. w: Writer;
  399. r: Reader;
  400. i: LONGINT;
  401. BEGIN{EXCLUSIVE}
  402. IF writers.Length() # 0 THEN
  403. FOR i := 0 TO writers.Length()-1 DO
  404. w := writers.Get(i)(Writer);
  405. ctx.out.String("writer (ID="); ctx.out.Int(w.id,0); ctx.out.String("):"); ctx.out.Ln;
  406. DoReportWriter(w.id,ctx);
  407. ctx.out.Ln;
  408. END;
  409. ELSE
  410. ctx.out.String("no TestFs writer is running"); ctx.out.Ln;
  411. END;
  412. IF readers.Length() # 0 THEN
  413. FOR i := 0 TO readers.Length()-1 DO
  414. r := readers.Get(i)(Reader);
  415. ctx.out.String("reader (ID="); ctx.out.Int(r.id,0); ctx.out.String("):"); ctx.out.Ln;
  416. DoReportReader(r.id,ctx);
  417. ctx.out.Ln;
  418. END;
  419. ELSE
  420. ctx.out.String("no TestFs reader is running"); ctx.out.Ln;
  421. END;
  422. END Report;
  423. BEGIN
  424. NEW(writers,8);
  425. NEW(readers, 8);
  426. END TestFs.
  427. SystemTools.DoCommands
  428. TFTPServer.Start ~
  429. OEB.NewServer --type=Auto
  430. PLAN
  431. setsource TFTP 10.3.34.188
  432. mount A2 SD0 3
  433. load A2.Bin a2
  434. load build/TestFs.Gof t
  435. deploy t file A2:TestFs.Gof
  436. setinput auto.txt
  437. END
  438. ~
  439. (*OEB.NewServer --type=Interactive ~*)
  440. OEB.NewInterface --type=Udp --server=0 ~
  441. OEB.Server --start --all ~
  442. OEB.Interface --start --all --server=0 ~
  443. ~
  444. SystemTools.DoCommands
  445. TFTPServer.Start ~
  446. OEB.NewServer --type=Interactive ~
  447. OEB.NewInterface --type=Udp --server=0 ~
  448. OEB.Server --start --all ~
  449. OEB.Interface --start --all --server=0 ~
  450. ~
  451. StaticLinker.Link --fileName=A2.Bin --displacement=100000H -a --path=build/
  452. Runtime Initializer Platform FPE64 ARMRuntime Trace BootConfig Uart Machine Heaps Modules Objects Kernel KernelLog Plugins
  453. Streams Pipes Commands Reals Clock Dates Strings Files Disks Reflection TrapWriters Traps Locks Options PsConfig SdEnvironment
  454. Sd SdDisks SdControllers Caches DiskVolumes DiskFS BitSets StringPool ObjectFile Diagnostics GenericLinker GenericLoader
  455. BootConsole
  456. ~
  457. OEB.Command --server=0 --id=0
  458. setsource TFTP 10.3.34.188
  459. mount A2 SD0 3
  460. load A2.Bin a2
  461. save a2
  462. setinput auto.txt
  463. ~
  464. save a2
  465. ~
  466. OEB.Command --server=0 --id=0
  467. setsource TFTP 10.3.34.188
  468. mount A2 SD0 3
  469. deployfile build/TestFs.Gof A2:TestFs.Gof
  470. ~
  471. OEB.Command --server=0 --id=0
  472. start
  473. ~
  474. OEB.Command --server=0 --id=0
  475. setinput auto.txt
  476. ~
  477. OEB.Command --server=0 --id=0
  478. reset
  479. ~
  480. OEB.Interface --show --all --server=0 ~
  481. OEB.Server --show --all ~
  482. OEB.Session --show --all ~
  483. OEB.Server --kill --all ~
  484. SystemTools.FreeDownTo OEBInterfaces ~
  485. SystemTools.FreeDownTo UDP ~
  486. mount DATA AosFS SD0#4 '|' N
  487. TestFs.StartWriter 1234567 DATA:TestFs-1234567.dat 1000000000
  488. TestFs.StartWriter 7654321 DATA:TestFs-7654321.dat 1000000000
  489. TestFs.StartReader 1234567 DATA:TestFs-123457.dat 1000000000
  490. TestFs.StartReader 7654321 DATA:TestFs-7654321.dat
  491. TestFs.ReportWriter 1234567
  492. TestFs.ReportWriter 7654321
  493. TestFs.ReportReader 1234567
  494. TestFs.ReportReader 1234567
  495. asd