From db15cbc71b5521d36057ddf19d7bfed6b8c95e22 Mon Sep 17 00:00:00 2001
From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr>
Date: Mon, 17 May 2021 11:57:01 +0200
Subject: [PATCH] feat(tests for drive programm added)
---
tpfs/Makefile | 3 ++-
tpfs/drive-test.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 tpfs/drive-test.c
diff --git a/tpfs/Makefile b/tpfs/Makefile
index 49b441c..bd26ba1 100644
--- a/tpfs/Makefile
+++ b/tpfs/Makefile
@@ -13,7 +13,7 @@ LIBS = -L$(LIBDIR) -lhardware
###------------------------------
### Main targets
###------------------------------------------------------------
-BINARIES= mkhd display_sector format_sector write_sector mkvol dvol rmvol mknfs dfs
+BINARIES= mkhd display_sector format_sector write_sector mkvol dvol rmvol mknfs dfs drive-test
all: $(BINARIES) $(OBJECTS)
@@ -36,6 +36,7 @@ dvol: dvol.o vol.o drive.o
rmvol: rmvol.o vol.o drive.o
mknfs: mknfs.o vol.o drive.o
dfs: dfs.o vol.o drive.o
+drive-test: drive-test.o drive.o
###------------------------------
### Misc.
diff --git a/tpfs/drive-test.c b/tpfs/drive-test.c
new file mode 100644
index 0000000..c456c83
--- /dev/null
+++ b/tpfs/drive-test.c
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "hardware.h"
+#include "drive.h"
+
+static void
+empty_it()
+{
+ return;
+}
+
+int main(int argc, char const *argv[])
+{
+ unsigned int i;
+ unsigned char buffer[HDA_SECTORSIZE];
+
+ /* init hardware */
+ if (init_hardware("hwconfig.ini") == 0)
+ {
+ fprintf(stderr, "Error in hardware initialization\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Interreupt handlers */
+ for (i = 0; i < 16; i++)
+ IRQVECTOR[i] = empty_it;
+
+ /* Allows all IT */
+ _mask(1);
+
+ printf("> Lecture du disque: \n");
+ printf("\t> Numero de cylindre: 0 \n");
+ printf("\t> Numero de secteur: 0 \n\n");
+ read_sector(buffer, 0, 0);
+ dump(buffer, HDA_SECTORSIZE, 0, 1);
+
+ printf("\n> Formattage du disque: \n");
+ printf("\t> Numero de cylindre: 0 \n");
+ printf("\t> Numero de secteur: 0 \n");
+ printf("\t> Donnée à écrire: 0xCAFEBABE \n");
+ format_sector(0, 0, 0x1, 0xCAFEBABE);
+ printf(">Formatage terminé\n\n");
+
+ printf("> Lecture du disque: \n");
+ printf("\t> Numero de cylindre: 0 \n");
+ printf("\t> Numero de secteur: 0 \n\n");
+ read_sector(buffer, 0, 0);
+ dump(buffer, HDA_SECTORSIZE, 0, 1);
+
+ printf("\n> Ecriture du disque: \n");
+ printf("\t> Numero de cylindre: 0 \n");
+ printf("\t> Numero de secteur: 0 \n");
+ printf("\t> Donnée à écrire: deadbeef \n");
+ write_sector(0, 0, (unsigned char *)"deadbeef");
+ printf("> Ecriture terminée\n\n");
+
+ printf("> Lecture du disque: \n");
+ printf("\t> Numero de cylindre: 0 \n");
+ printf("\t> Numero de secteur: 0 \n\n");
+ read_sector(buffer, 0, 0);
+ dump(buffer, HDA_SECTORSIZE, 0, 1);
+
+ /* and exit! */
+ exit(EXIT_SUCCESS);
+}
--
GitLab