add test_net.c

This commit is contained in:
lr 2024-05-17 18:07:26 +08:00
parent 59c1edce98
commit bcc5251dc0
6 changed files with 7 additions and 10 deletions

View File

@ -89,7 +89,7 @@ test_priority: test_priority.o libserial.o printf.o usyscall.o arch_usyscall.o l
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
test_net:test_fs.o lwip_service.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o
test_net: test_net.o lwip_service.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm

View File

@ -12,10 +12,6 @@
// test_net: Test the lwip network stack
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "libserial.h"
#include "lwip_service.h"
#include "usyscall.h"
@ -32,7 +28,7 @@ int main(int argc, char* argv[])
char lwip_gwaddr[4] = { 192, 168, 130, 1 };
LWIP_init(&sess, lwip_ipaddr, lwip_netmask, lwip_ipaddr);
free_session(&session);
free_session(&sess);
exit(0);
return 0;

View File

@ -18,13 +18,13 @@
// Block size
#define BLOCK_SIZE 512
#define NR_BIT_BLOCKS 4
#define NR_BIT_BLOCKS 8
// bits size
#define BITS 8
// Bitmap size of one block
#define BITMAP_SIZE (BLOCK_SIZE * BITS * NR_BIT_BLOCKS)
#define BITMAP_SIZE (BLOCK_SIZE * BITS)
// Inode size of one block
#define INODE_SIZE (BLOCK_SIZE / sizeof(struct Inode))

View File

@ -17,3 +17,4 @@ void LWIP_init(struct Session* session, char* ip, char* mask, char* gw){
IPC_CALL(Ipc_LWIP_init)(session, ip, mask, gw);
}

View File

@ -263,8 +263,8 @@ void balloc(int used)
uchar buf[BLOCK_SIZE];
int i;
printf("balloc: first %d blocks have been allocated\n", used);
bzero(buf, BLOCK_SIZE);
for (int bmsec = 0; bmsec < bitblocks; bmsec++) {
bzero(buf, BLOCK_SIZE);
for (i = 0; i < ((used > NR_BIT_PER_BYTE * BLOCK_SIZE) ? NR_BIT_PER_BYTE * BLOCK_SIZE : used); i++) {
buf[i / NR_BIT_PER_BYTE] = buf[i / NR_BIT_PER_BYTE] | (0x1 << (i % NR_BIT_PER_BYTE));
}

View File

@ -49,7 +49,7 @@ Modification:
#define ROOT_INUM 1 // root inode number
#define BLOCK_SIZE 512 // block size
#define NR_BIT_PER_BYTE 8
#define NR_BIT_BLOCKS 4
#define NR_BIT_BLOCKS 8
#define nr_blocks_total (BLOCK_SIZE * NR_BIT_PER_BYTE * NR_BIT_BLOCKS) // total number of blocks (including used blocks and free blocks)
#define nr_inodes 200 // total number of inodes