1#!/usr/bin/env omake 2#---------------------------------------------------------------------------- 3# Project: Horizon 4# File: testutil.om 5# 6# Copyright 2007-2009 Nintendo. All rights reserved. 7# 8# These coded instructions, statements, and computer programs contain 9# proprietary information of Nintendo of America Inc. and/or Nintendo 10# Company Ltd., and are protected by Federal copyright law. They may 11# not be disclosed to third parties or copied or duplicated in any form, 12# in whole or in part, without the prior written consent of Nintendo. 13# 14# $Date:: 2010-08-20#$ 15# $Rev: 24283 $ 16# $Author: takiguchi_shinichi $ 17#---------------------------------------------------------------------------- 18 19LOADRUN = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)ctr_loadrunf32.exe) 20 21# UNIQUE_ID ���w�肵�� cia �����܂��B 22public.MakeCiaByID(filename, id, sources, rsf) = 23 depends = 24 CTR_APPTYPE = NAND 25 objects[] = 26 target_program = $(filename) 27 UNIQUE_ID = 0x$(id) 28 MAKEROMFLAGS += -DUNIQUE_ID=$(UNIQUE_ID) 29 TITLE = $(filename) 30 ROM_SPEC_FILE = $(rsf) 31 32 section 33 if $(defined TESTCIA_ROMFS_ROOT) 34 ROMFS_ROOT = $(TESTCIA_ROMFS_ROOT) 35 export ROMFS_ROOT 36 else 37 ROMFS_ROOT = 38 export ROMFS_ROOT 39 40 foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS))) 41 if $(defined UserRunProcess) 42 depends += $(UserRunProcess $(target), $(target_program), $(sources) $(objects)) 43 export depends 44 else 45 depends += $(UserProcess $(target), $(target_program), $(sources) $(objects)) 46 export depends 47 export depends 48 export depends 49 50 return $(filter %$(EXT_CIA), $(depends)) 51 52# UNIQUE_ID �͈̔͂��w�肵�� cia �����܂��B 53public.MakeCiaByIDRange(id_s, id_e, sources, rsf) = 54 depends = 55 id_s_denary = $(int 0x$(id_s)) 56 id_e_denary = $(int 0x$(id_e)) 57 idx = $(id_s_denary) 58 while $(lt $(idx), $(add $(id_e_denary), 1)) 59 id_hex = $(sprintf $"%05X", $(idx)) 60 depends += $(MakeCiaByID $(id_hex), $(id_hex), $(sources), $(rsf)) 61 idx = $(add $(idx), 1) 62 return $(depends) 63 64# cfa ���쐬���܂��B�i�o�͐�w��t�j 65public.FileArchiveWithOutdir(srcdir, outdir, rsf) = 66 name = $(basename $(srcdir)) 67 SOURCES_BASE_ROOT = $(dirname $(srcdir)) 68 CFAFile = $(makeDirectory $(outdir))$(DIRSEP)$(name)$(EXT_CFA) 69 70 if $(not $(defined ARCHIVE_DEPENDENCIES)) 71 ARCHIVE_DEPENDENCIES = $(ls -R, $(dir $(srcdir))) 72 export 73 ARCHIVE_DEPENDENCIES += $(rsf) 74 75 $(CFAFile): $(makeDirectory $(dirname $(CFAFile))) 76 $(CFAFile): $(srcdir) $(MAKEROM) $(rsf) $(ARCHIVE_DEPENDENCIES) 77 $(MAKEROM) -o $@ -DROMFS_ROOT=$(srcdir) $(MAKEROMFLAGS) -f data -rsf $(rsf) 78 79 return $(CFAFile) 80 81# �R���e���c���܂� cia �����܂��B 82public.MakeCiaWithContents(filename, contents, rsf) = 83 depends = 84 CTR_APPTYPE = NAND 85 title_contents[] = 86 target_title = $(filename) 87 TITLE = $(filename) 88 UNIQUE_ID = 0xFE000 89 MAKEROMFLAGS += -DUNIQUE_ID=$(UNIQUE_ID) 90 ROM_SPEC_FILE = $(rsf) 91 92 idx = 0 93 foreach(content, $(contents)) 94 title_contents += $(idx)>$(content) 95 idx = $(add $(idx), 1) 96 export 97 98 if $(defined Title) 99 foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS))) 100 depends += $(Title $(target), $(target_title), $(title_contents)) 101 export depends 102 export depends 103 104 return $(depends) 105 106# �}�j���A�����܂� cia �����܂��B 107public.MakeCiaWithManual(filename, id, sources, rsf, manualdir) = 108 section 109 MANUAL_DIR = $(manualdir) 110 return $(MakeCiaByID $(filename), $(id), $(sources), $(rsf)) 111 112# �C�ӂ̑傫���̃t�@�C�������܂��B 113public.MakeSpecifiedSizeFile(datafile, filesize) = 114 filedir = $(dirname $(datafile)) 115 $(datafile): $(makeDirectory $(filedir)) 116 section 117 rm -f $(filedir)/* 118 f = $(fopen $@, w) 119 idx = 0 120 while $(lt $(idx), $(filesize)) 121 fprint($(f), A) 122 idx = $(add $(idx), 1) 123 close($(f)) 124 return $(datafile) 125 126# romfs �ɔC�ӂ̑傫���̃t�@�C�������� cia �����܂��B 127public.MakeCiaWithRomfs(filename, id, filesize, sources, rsf) = 128 section 129 TESTCIA_ROMFS_ROOT = $(getOutputBaseDirectory)/$(SUBDIR_OBJECTS)/$(getModuleSubDirectory)/files_$(id) 130 datafile = $(TESTCIA_ROMFS_ROOT)/data.txt 131 ROMFS_DEPENDENCIES = $(MakeSpecifiedSizeFile $(datafile), $(filesize)) 132 return $(MakeCiaByID $(filename), $(id), $(sources), $(rsf)) 133 134# �t�@�C���� romfs_dir �փR�s�[���܂��B 135public.CopyIntoRomfsroot(romfs_dir, srces) = 136 copiedfiles = 137 138 foreach(TARGET, $(BUILDER.getTargets $(SUPPORTED_TARGETS))) 139 foreach(src, $(srces)) 140 filename = $(basename $(src)) 141 romfsroot = $(TARGET.getImageDirectory false)/$(romfs_dir) 142 copiedfile = $(romfsroot)/$(filename) 143 copiedfiles += $(copiedfile) 144 $(copiedfile): $(src) $(makeDirectory $(romfsroot)) 145 cp $(src) $(copiedfile) 146 export copiedfiles 147 export copiedfiles 148 149 return $(copiedfiles) 150 151# �^�[�Q�b�g�ʂɐ�������Ă���t�@�C���� romfs_dir �փR�s�[���܂��B 152public.CopyIntoRomfsrootFilteredByTarget(romfs_dir, srces) = 153 copiedfiles = 154 155 foreach(TARGET, $(BUILDER.getTargets $(SUPPORTED_TARGETS))) 156 target_srces = 157 foreach(src, $(srces)) 158 dirs = $(split /, $(split \\, $(src))) 159 if $(and $(mem $(TARGET.getFullnameWithSystem Process), $(dirs)), $(mem $(TARGET.buildtype), $(dirs))) 160 target_srces += $(src) 161 export target_srces 162 export target_srces 163 164 foreach(src, $(target_srces)) 165 filename = $(basename $(src)) 166 romfsroot = $(TARGET.getImageDirectory false)/$(romfs_dir) 167 copiedfile = $(romfsroot)/$(filename) 168 copiedfiles += $(copiedfile) 169 $(copiedfile): $(src) $(makeDirectory $(romfsroot)) 170 cp $(src) $(copiedfile) 171 export copiedfiles 172 export copiedfiles 173 174 return $(copiedfiles) 175 176# �t�@�C�����J���A��s���ǂݍ��݂܂��B 177public.ReadFileLine(filename) = 178 f = $(fopen $(filename), r) 179 result = 180 while true 181 try 182 result += $(input-line $(f)) 183 export result 184 catch RuntimeException(e) 185 break() 186 export result 187 close($(f)) 188 return $(result) 189 190# PC��̃v���O���������s����N���X�ł��B 191HostProgramRunner. = 192 class HostProgramRunner 193 194 program = 195 196 new(program) = 197 this.program = $(program) 198 return $(this) 199 200 run() = 201 $(program) & 202 203public.MakeHostProgramRunner(program) = 204 return $(HostProgramRunner.new $(program)) 205 206ProgramRunner. = 207 class ProgramRunner 208 209 new(program, exitpattern, timeout) = 210 this.program = $(program) 211 this.exitPattern = $(exitpattern) 212 this.timeOut = $(timeout) 213 return $(this) 214 215 run(options, logfile) = 216 echo $(LOADRUN) $(options) -re $(program) -e $(exitPattern) -t $(timeOut) | tee $(logfile) 217 $(LOADRUN) $(options) -re $(program) -e $(exitPattern) -t $(timeOut) | tee $(logfile) 218 219public.MakeProgramRunner(program, exitpattern, timeout) = 220 return $(ProgramRunner.new $(program),$(exitpattern),$(timeout)) 221 222public.GetToolPath(programName, ext) = 223 return $(HORIZON_ROOT_IMAGES)$(DIRSEP)tools$(DIRSEP)$(programName)$(DIRSEP)$`(TARGET.getFullnameWithSystem Process)$(DIRSEP)$`(TARGET.buildtype)$(DIRSEP)$(programName)$(ext) 224 225# �w�肳�ꂽ���O�̃v���Z�X�� CDI �̃p�X��Ԃ��܂��B 226public.GetProcessCdiPath(processName) = 227 return @$(HORIZON_ROOT_IMAGES)$(DIRSEP)processes$(DIRSEP)$(processName)$(DIRSEP)$`(TARGET.getFullnameWithSystem Process)$(DIRSEP)$`(TARGET.buildtype)$(DIRSEP)$(processName).cdi 228 229# �w�肳�ꂽ�����̃v���Z�X��CDI�̃p�X��Ԃ��܂��B 230public.GetProcessCdiPathList(processNames) = 231 if $(eq 1, $(length processNames)) 232 return $(GetProcessCdiPath $(processNames)) 233 234 pathlist = $(GetProcessCdiPath $(nth 0, $(processNames))) 235 236 foreach(proc, $(nth-tl 1, $(processNames))) 237 pathlist += ,$(GetProcessCdiPath $(proc)) 238 export 239 240 return $(pathlist) 241