yaffs Added a new test for yaffs functions via linux command calls.
[yaffs2.git] / direct / timothy_tests / linux_tests / lib.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "lib.h"
15 static char message[200];
16 static int  PRINT_LEVEL = 3;
17
18 node * linked_list_add_node(int pos,node *head_node)
19 {
20         node *new_node=NULL;
21         if (pos==HEAD){
22                 new_node=malloc(sizeof(node));
23                 memset(new_node, NULL, sizeof(node));
24                 new_node->string=NULL;
25                 new_node->next=head_node;
26                 return new_node;
27         }
28         return NULL;
29 }
30
31 void node_print_pointers(node *current_node)
32 {
33         while (current_node != NULL){
34                 sprintf(message,"current_node: %p, string: %s next_node: %p\n",current_node,current_node->string,current_node->next);
35                 print_message(3,message);
36                 current_node=current_node->next;
37         }
38 }
39
40 int delete_linked_list(node *head_node)
41 {
42         node *next_node=NULL;
43         node *current_node=head_node;
44
45                 while (current_node != NULL){
46                         next_node=current_node->next;
47                         free(current_node);
48                         current_node=next_node;
49                 }
50
51         return 1;
52 }
53
54 char * generate_random_string(unsigned int length)
55 {
56         char string[length+1];
57         unsigned int x;
58         for (x=0;x<(length-1);x++)
59         {
60                 string[x]=(rand() % NAME_RANGE)+65;
61         }
62         string[x]='\0';
63         return string;
64 }
65 void set_print_level(int new_level)
66 {
67         PRINT_LEVEL=new_level;
68 }
69 int get_print_level(void)
70 {
71         return PRINT_LEVEL;
72 }
73 void print_message(char print_level,char *message)
74 {
75         if (print_level <= PRINT_LEVEL){
76                 printf(message);
77         }
78 }
79 unsigned int random_int(void)
80 {
81         return (random()%4294967295);
82 }
83
84 void check_function(int output)
85 {
86         if (output>=0){
87                 print_message(3,"test_passed\n");
88         } else {
89                 print_message(3,"test_failed\n");
90                 get_error_linux();
91         }
92 }
93
94 void get_error_linux(void)
95 {
96         int error_code=0;
97         char message[30];
98         message[0]='\0';
99
100         error_code=errno;
101         sprintf(message,"linux_error code %d\n",error_code);
102         print_message(1,message);
103         
104         strcpy(message,"error is");
105         perror(message);
106 //      sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
107         //perror(message);      
108         //print_message(1,message);
109 }