]>
Commit | Line | Data |
---|---|---|
94b17fa1 | 1 | /** @file\r |
2 | This is a simple shell application\r | |
3 | \r | |
4 | This should be executed with "/Param2 Val1" and "/Param1" as the 2 command line options!\r | |
5 | \r | |
9b3bf083 | 6 | Copyright (c) 2008-2009, Intel Corporation \r |
94b17fa1 | 7 | All rights reserved. This program and the accompanying materials \r |
8 | are licensed and made available under the terms and conditions of the BSD License \r | |
9 | which accompanies this distribution. The full text of the license may be found at \r | |
10 | http://opensource.org/licenses/bsd-license.php \r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
18 | #include <Library/UefiApplicationEntryPoint.h>\r | |
19 | #include <Library/UefiLib.h>\r | |
20 | #include <Library/ShellLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Library/MemoryAllocationLib.h>\r | |
23 | \r | |
24 | SHELL_PARAM_ITEM ParamList[] = {\r | |
25 | {L"/Param1", TypeFlag},\r | |
26 | {L"/Param2", TypeValue},\r | |
27 | {NULL, TypeMax}};\r | |
28 | \r | |
29 | /**\r | |
30 | as the real entry point for the application.\r | |
31 | \r | |
32 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
33 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
34 | \r | |
35 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
36 | @retval other Some error occurs when executing this entry point.\r | |
37 | \r | |
38 | **/\r | |
39 | EFI_STATUS\r | |
40 | EFIAPI\r | |
41 | UefiMain (\r | |
42 | IN EFI_HANDLE ImageHandle,\r | |
43 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
44 | )\r | |
45 | {\r | |
46 | EFI_FILE_HANDLE FileHandle;\r | |
47 | EFI_STATUS Status;\r | |
48 | CHAR16 FileName[100];\r | |
49 | UINTN BufferSize;\r | |
50 | UINT64 Position;\r | |
51 | UINT8 Buffer[200];\r | |
52 | EFI_FILE_INFO *pFileInfo;\r | |
53 | UINT64 Size;\r | |
54 | BOOLEAN NoFile;\r | |
d2b4564b | 55 | EFI_SHELL_FILE_INFO *pShellFileInfo;\r |
94b17fa1 | 56 | LIST_ENTRY *List;\r |
57 | \r | |
58 | FileHandle = NULL;\r | |
59 | StrCpy(FileName, L"testfile.txt");\r | |
60 | Position = 0;\r | |
61 | pFileInfo = NULL;\r | |
62 | Size = 0;\r | |
63 | NoFile = FALSE;\r | |
64 | pShellFileInfo = NULL;\r | |
65 | List = NULL;\r | |
66 | \r | |
67 | ASSERT(ShellGetExecutionBreakFlag() == FALSE);\r | |
68 | ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f8:\\") == 0);\r | |
69 | Print(L"execution break and get cur dir - pass\r\n");\r | |
70 | \r | |
71 | ShellSetPageBreakMode(TRUE);\r | |
72 | \r | |
73 | Status = ShellOpenFileByName(FileName, \r | |
74 | &FileHandle, \r | |
75 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
76 | 0\r | |
77 | );\r | |
78 | ASSERT_EFI_ERROR(Status);\r | |
79 | \r | |
80 | BufferSize = StrSize(FileName);\r | |
81 | Status = ShellWriteFile(FileHandle, &BufferSize, FileName);\r | |
82 | ASSERT_EFI_ERROR(Status);\r | |
83 | Status = ShellGetFilePosition(FileHandle, &Position);\r | |
84 | ASSERT_EFI_ERROR(Status);\r | |
85 | ASSERT(Position == 0x1A);\r | |
86 | Status = ShellSetFilePosition(FileHandle, 0);\r | |
87 | ASSERT_EFI_ERROR(Status);\r | |
88 | BufferSize = sizeof(Buffer) * sizeof(Buffer[0]);\r | |
89 | Status = ShellReadFile(FileHandle, &BufferSize, Buffer);\r | |
90 | ASSERT_EFI_ERROR(Status);\r | |
91 | ASSERT(BufferSize == 0x1A);\r | |
92 | ASSERT(StrCmp((CHAR16*)Buffer, FileName) == 0);\r | |
93 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
94 | ASSERT(pFileInfo != NULL);\r | |
95 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
96 | ASSERT(pFileInfo->FileSize == 0x1A);\r | |
97 | FreePool(pFileInfo);\r | |
98 | pFileInfo = NULL;\r | |
99 | Status = ShellCloseFile(&FileHandle);\r | |
94b17fa1 | 100 | ASSERT_EFI_ERROR(Status);\r |
101 | Print(L"read, write, create, getinfo - pass\r\n");\r | |
102 | \r | |
103 | Status = ShellOpenFileByName(FileName, \r | |
104 | &FileHandle, \r | |
105 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
106 | 0\r | |
107 | );\r | |
108 | ASSERT_EFI_ERROR(Status);\r | |
109 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
110 | ASSERT(pFileInfo != NULL);\r | |
111 | pFileInfo->FileSize = 0x20;\r | |
112 | Status = ShellSetFileInfo(FileHandle, pFileInfo);\r | |
113 | FreePool(pFileInfo);\r | |
114 | pFileInfo = NULL; \r | |
115 | ASSERT_EFI_ERROR(Status);\r | |
116 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
117 | ASSERT(pFileInfo != NULL);\r | |
118 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
119 | ASSERT(pFileInfo->PhysicalSize == 0x20);\r | |
120 | ASSERT(pFileInfo->FileSize == 0x20);\r | |
121 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
122 | FreePool(pFileInfo);\r | |
123 | Status = ShellGetFileSize(FileHandle, &Size);\r | |
124 | ASSERT(Size == 0x20);\r | |
125 | ASSERT_EFI_ERROR(Status);\r | |
126 | Status = ShellCloseFile(&FileHandle);\r | |
94b17fa1 | 127 | ASSERT_EFI_ERROR(Status);\r |
128 | Print(L"setinfo and change size, getsize - pass\r\n");\r | |
129 | \r | |
130 | Status = ShellOpenFileByName(FileName, \r | |
131 | &FileHandle, \r | |
132 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
133 | 0\r | |
134 | );\r | |
135 | ASSERT_EFI_ERROR(Status);\r | |
136 | \r | |
137 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
138 | ASSERT(pFileInfo != NULL);\r | |
139 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
140 | ASSERT(pFileInfo->PhysicalSize == 0x20);\r | |
141 | ASSERT(pFileInfo->FileSize == 0x20);\r | |
142 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
143 | FreePool(pFileInfo);\r | |
144 | pFileInfo = NULL; \r | |
145 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 146 | ASSERT_EFI_ERROR(Status);\r |
147 | Print(L"reopen file - pass\r\n");\r | |
148 | \r | |
149 | Status = ShellOpenFileByName(FileName, \r | |
150 | &FileHandle, \r | |
151 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
152 | 0\r | |
153 | );\r | |
154 | ASSERT_EFI_ERROR(Status);\r | |
155 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
156 | ASSERT(pFileInfo != NULL);\r | |
157 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
158 | ASSERT(pFileInfo->PhysicalSize == 0x0);\r | |
159 | ASSERT(pFileInfo->FileSize == 0x0);\r | |
160 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
161 | FreePool(pFileInfo);\r | |
162 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 163 | ASSERT_EFI_ERROR(Status);\r |
164 | Print(L"size of empty - pass\r\n");\r | |
165 | \r | |
166 | Status = ShellOpenFileByName(FileName, \r | |
167 | &FileHandle, \r | |
168 | EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
169 | 0\r | |
170 | );\r | |
171 | ASSERT(Status == EFI_NOT_FOUND);\r | |
172 | ASSERT(FileHandle == NULL);\r | |
173 | \r | |
174 | Status = ShellCreateDirectory(FileName, &FileHandle);\r | |
175 | ASSERT_EFI_ERROR(Status);\r | |
176 | ASSERT(FileHandle != NULL);\r | |
177 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
178 | ASSERT(pFileInfo != NULL);\r | |
179 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
180 | ASSERT(pFileInfo->Attribute&EFI_FILE_DIRECTORY);\r | |
181 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 182 | ASSERT_EFI_ERROR(Status);\r |
183 | Print(L"Directory create - pass\r\n");\r | |
184 | \r | |
185 | // FindFirst and FindNext\r | |
186 | StrCpy(FileName, L"testDir");\r | |
187 | Status = ShellCreateDirectory(FileName, &FileHandle);\r | |
188 | Status = ShellCloseFile(&FileHandle);\r | |
189 | StrCat(FileName, L"\\File.txt");\r | |
190 | Status = ShellOpenFileByName(FileName, \r | |
191 | &FileHandle, \r | |
192 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
193 | 0\r | |
194 | );\r | |
195 | ASSERT_EFI_ERROR(Status);\r | |
196 | Status = ShellCloseFile(&FileHandle);\r | |
197 | StrCpy(FileName, L"testDir");\r | |
198 | Status = ShellOpenFileByName(FileName, \r | |
199 | &FileHandle, \r | |
200 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
201 | 0\r | |
202 | );\r | |
203 | ASSERT_EFI_ERROR(Status);\r | |
d2b4564b | 204 | Status = ShellFindFirstFile(FileHandle, &pFileInfo);\r |
94b17fa1 | 205 | ASSERT_EFI_ERROR(Status);\r |
206 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
207 | ASSERT_EFI_ERROR(Status);\r | |
208 | ASSERT(NoFile == FALSE);\r | |
209 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
210 | ASSERT_EFI_ERROR(Status);\r | |
211 | ASSERT(NoFile == FALSE);\r | |
212 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
213 | ASSERT_EFI_ERROR(Status);\r | |
9b3bf083 | 214 | ///@todo - why is NoFile never set? limitation of NT32 file system?\r |
94b17fa1 | 215 | Status = ShellDeleteFile(&FileHandle);\r |
94b17fa1 | 216 | ASSERT(Status == RETURN_WARN_DELETE_FAILURE);\r |
217 | Print(L"FindFirst - pass\r\n");\r | |
218 | Print(L"FindNext - Verify with real EFI system. Cant verify NoFile under NT32\r\n");\r | |
219 | \r | |
220 | // open and close meta arg\r | |
221 | Status = ShellOpenFileMetaArg(L"testDir\\*.*", EFI_FILE_MODE_READ, &pShellFileInfo);\r | |
222 | ASSERT_EFI_ERROR(Status);\r | |
223 | ASSERT(pShellFileInfo->Status == 0);\r | |
224 | ASSERT(StrCmp(pShellFileInfo->FileName, L"File.txt") == 0);\r | |
225 | ASSERT(pShellFileInfo->Handle);\r | |
226 | ASSERT(pShellFileInfo->Info);\r | |
227 | ASSERT(pShellFileInfo->Info->FileSize == 0);\r | |
228 | ASSERT(StrCmp(pShellFileInfo->Info->FileName, L"File.txt") == 0);\r | |
229 | ASSERT(pShellFileInfo->Info->Attribute == 0);\r | |
d2b4564b | 230 | \r |
94b17fa1 | 231 | Status = ShellCloseFileMetaArg(&pShellFileInfo);\r |
232 | ASSERT_EFI_ERROR(Status);\r | |
233 | Print(L"Open/Close Meta Arg - pass\r\n");\r | |
234 | \r | |
235 | // now delete that file and that directory\r | |
236 | StrCat(FileName, L"\\File.txt");\r | |
237 | Status = ShellOpenFileByName(FileName, \r | |
238 | &FileHandle, \r | |
239 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
240 | 0\r | |
241 | );\r | |
242 | ASSERT_EFI_ERROR(Status);\r | |
243 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 244 | StrCpy(FileName, L"testDir");\r |
245 | ASSERT_EFI_ERROR(Status);\r | |
246 | Status = ShellOpenFileByName(FileName, \r | |
247 | &FileHandle, \r | |
248 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
249 | 0\r | |
250 | );\r | |
251 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 252 | ASSERT_EFI_ERROR(Status);\r |
253 | \r | |
254 | // get environment variable\r | |
255 | // made for testing under nt32\r | |
256 | ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f8:\\efi\\tools;f8:\\efi\\boot;f8:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);\r | |
257 | Print(L"ShellGetEnvironmentVariable - pass\r\n");\r | |
258 | \r | |
259 | // set environment variable\r | |
260 | Status = ShellSetEnvironmentVariable(L"", L"", FALSE);\r | |
261 | ASSERT(Status == EFI_UNSUPPORTED);\r | |
262 | Print(L"ShellSetEnvironmentVariable - pass\r\n");\r | |
263 | \r | |
264 | // ShellExecute\r | |
265 | Status = ShellExecute(&ImageHandle, L"EmptyApplication.efi", TRUE, NULL, NULL);\r | |
266 | ASSERT_EFI_ERROR(Status);\r | |
267 | // the pass printout for this is performed by EmptyApplication\r | |
268 | Print(L"\r\n");\r | |
269 | \r | |
270 | // command line param functions\r | |
271 | Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);\r | |
272 | // if you put an invalid parameter you SHOULD hit this assert.\r | |
273 | ASSERT_EFI_ERROR(Status);\r | |
274 | if (List) {\r | |
275 | ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);\r | |
276 | ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);\r | |
277 | ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);\r | |
d2b4564b | 278 | ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);\r |
94b17fa1 | 279 | \r |
280 | ShellCommandLineFreeVarList(List);\r | |
281 | } else {\r | |
282 | Print(L"param checking skipped.\r\n");\r | |
283 | }\r | |
284 | \r | |
285 | // page break mode (done last so we can see the results)\r | |
286 | // we set this true at the begining of the program\r | |
287 | // this is enough lines to trigger the page...\r | |
288 | Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n");\r | |
289 | ShellSetPageBreakMode(FALSE);\r | |
290 | Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n");\r | |
291 | \r | |
292 | return EFI_SUCCESS;\r | |
293 | }\r | |
294 | \r | |
295 | \r | |
296 | /*\r | |
297 | done - ShellGetFileInfo\r | |
298 | done - ShellSetFileInfo\r | |
299 | done - ShellOpenFileByDevicePath\r | |
300 | done - ShellOpenFileByName\r | |
301 | done - ShellCreateDirectory\r | |
302 | done - ShellReadFile\r | |
303 | done - ShellWriteFile\r | |
304 | done - ShellCloseFile\r | |
305 | done - ShellDeleteFile\r | |
306 | done - ShellSetFilePosition\r | |
307 | done - ShellGetFilePosition\r | |
308 | ???? - ShellFlushFile\r | |
309 | done - ShellFindFirstFile\r | |
310 | done - ShellFindNextFile\r | |
311 | done - ShellGetFileSize\r | |
312 | done - ShellGetExecutionBreakFlag\r | |
313 | done - ShellGetEnvironmentVariable\r | |
314 | done - ShellSetEnvironmentVariable\r | |
315 | done - ShellExecute\r | |
316 | done - ShellGetCurrentDir\r | |
317 | done - ShellSetPageBreakMode\r | |
318 | done - ShellOpenFileMetaArg\r | |
319 | done - ShellCloseFileMetaArg\r | |
320 | done - ShellCommandLineParse\r | |
321 | done - ShellCommandLineFreeVarList\r | |
322 | done - ShellCommandLineGetFlag\r | |
323 | done - ShellCommandLineGetValue\r | |
324 | done - ShellCommandLineGetRawValue\r | |
e9880e25 | 325 | */\r |