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)
20DEFAULT_RUN_TIMEOUT = 60
21DEFAULT_EXIT_PATTERN= $"CU_TEST_EXIT|KernelPanic|nn::svc::Break\("
22
23# Use makecia for debugging.
24public.UseMakeCiaDebug() =
25    MAKECIA      = $(ROOT_COMMANDS)$(DIRSEP)ctr_makeciadebug32.exe
26    export
27
28# Specify UNIQUE_ID and generate cia.
29public.MakeCiaByID(filename, id, sources, rsf) =
30    depends             =
31    CTR_APPTYPE         =   NAND
32    objects[]           =
33    target_program      =   $(filename)
34    UNIQUE_ID           =   0x$(id)
35    MAKEROMFLAGS       +=   -DUNIQUE_ID=$(UNIQUE_ID)
36    TITLE               =   $(filename)
37    ROM_SPEC_FILE       =   $(rsf)
38
39    if $(not $(defined DESCRIPTOR))
40        DESCRIPTOR      =   $(HORIZON_ROOT)/resources/specfiles/Application.desc
41        export
42
43    section
44        if $(defined TESTCIA_ROMFS_ROOT)
45            ROMFS_ROOT = $(TESTCIA_ROMFS_ROOT)
46            export ROMFS_ROOT
47        else
48            ROMFS_ROOT =
49            export ROMFS_ROOT
50
51        foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
52            if $(defined UserRunProcess)
53                depends += $(UserRunProcess $(target), $(target_program), $(sources) $(objects))
54                export depends
55            else
56                depends += $(UserProcess $(target), $(target_program), $(sources) $(objects))
57                export depends
58            export depends
59        export depends
60
61    return $(filter %$(EXT_CIA), $(depends))
62
63# Specify UNIQUE_ID range and generate cia.
64public.MakeCiaByIDRange(id_s, id_e, sources, rsf) =
65    depends =
66    id_s_denary = $(int 0x$(id_s))
67    id_e_denary = $(int 0x$(id_e))
68    idx = $(id_s_denary)
69    while $(lt $(idx), $(add $(id_e_denary), 1))
70        id_hex = $(sprintf $"%05X", $(idx))
71        depends += $(MakeCiaByID $(id_hex), $(id_hex), $(sources), $(rsf))
72        idx = $(add $(idx), 1)
73    return $(depends)
74
75# Create cfa. (With output destination specified)
76public.FileArchiveWithOutdir(srcdir, outdir, rsf) =
77    name = $(basename $(srcdir))
78    SOURCES_BASE_ROOT = $(dirname $(srcdir))
79    CFAFile = $(makeDirectory $(outdir))$(DIRSEP)$(name)$(EXT_CFA)
80
81    if $(not $(defined ARCHIVE_DEPENDENCIES))
82        ARCHIVE_DEPENDENCIES = $(ls -R, $(dir $(srcdir)))
83        export
84    ARCHIVE_DEPENDENCIES += $(rsf)
85
86    $(CFAFile): $(makeDirectory $(dirname $(CFAFile)))
87    $(CFAFile): $(srcdir) $(MAKEROM) $(rsf) $(ARCHIVE_DEPENDENCIES)
88        $(MAKEROM) -o $@ -DROMFS_ROOT=$(srcdir) $(MAKEROMFLAGS) -f data -rsf $(rsf)
89
90    return $(CFAFile)
91
92# Generate CIA that includes content.
93public.MakeCiaWithContents(filename, contents, rsf) =
94    depends             =
95    CTR_APPTYPE         =   NAND
96    title_contents[]    =
97    target_title        =   $(filename)
98    TITLE               =   $(filename)
99    UNIQUE_ID           =   0xFE000
100    MAKEROMFLAGS       +=   -DUNIQUE_ID=$(UNIQUE_ID)
101    ROM_SPEC_FILE       =   $(rsf)
102
103    idx = 0
104    foreach(content, $(contents))
105        title_contents += $(idx)>$(content)
106        idx = $(add $(idx), 1)
107        export
108
109    if $(defined Title)
110        foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
111            depends += $(Title $(target), $(target_title), $(title_contents))
112            export depends
113        export depends
114
115    return $(depends)
116
117# Generate CIA that includes a manual.
118public.MakeCiaWithManual(filename, id, sources, rsf, manualdir) =
119    section
120        MANUAL_DIR = $(manualdir)
121        return $(MakeCiaByID $(filename), $(id), $(sources), $(rsf))
122
123# Generate a file of any size.
124public.MakeSpecifiedSizeFile(datafile, filesize) =
125    filedir = $(dirname $(datafile))
126    $(datafile): $(makeDirectory $(filedir))
127        section
128            rm -f $(filedir)/*
129            f = $(fopen $@, w)
130            try
131                lseek($(f), $(sub $(filesize), 3), SEEK_SET)
132                fprint($(f), end)
133            catch RuntimeException(e)
134                idx = 0
135                while $(lt $(idx), $(filesize))
136                    fprint($(f), A)
137                    idx = $(add $(idx), 1)
138            close($(f))
139    return $(datafile)
140
141# Generate CIA that has a file of an arbitrary size to romfs.
142public.MakeCiaWithRomfs(filename, id, filesize, sources, rsf) =
143    section
144        TESTCIA_ROMFS_ROOT  =   $(getOutputBaseDirectory)/$(SUBDIR_OBJECTS)/$(getModuleSubDirectory)/files_$(id)
145        datafile            =   $(TESTCIA_ROMFS_ROOT)/data.txt
146        ROMFS_DEPENDENCIES  =   $(MakeSpecifiedSizeFile $(datafile), $(filesize))
147        return $(MakeCiaByID $(filename), $(id), $(sources), $(rsf))
148
149# Copy a file to romfs_dir.
150public.CopyIntoRomfsroot(romfs_dir, srces) =
151    copiedfiles =
152
153    foreach(TARGET, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
154        foreach(src, $(srces))
155            filename = $(basename $(src))
156            romfsroot = $(TARGET.getImageDirectory false)/$(romfs_dir)
157            copiedfile = $(romfsroot)/$(filename)
158            copiedfiles += $(copiedfile)
159            $(copiedfile): $(src) $(makeDirectory $(romfsroot))
160                cp $(src) $(copiedfile)
161            export copiedfiles
162        export copiedfiles
163
164    return $(copiedfiles)
165
166# Copy files generated for separate targets to romfs_dir.
167public.CopyIntoRomfsrootFilteredByTarget(romfs_dir, srces) =
168    copiedfiles =
169
170    foreach(TARGET, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
171        target_srces =
172        foreach(src, $(srces))
173            dirs = $(split /, $(split \\, $(src)))
174            if $(and $(mem $(TARGET.getFullnameWithSystem Process), $(dirs)), $(mem $(TARGET.buildtype), $(dirs)))
175                target_srces += $(src)
176                export target_srces
177            export target_srces
178
179        foreach(src, $(target_srces))
180            filename = $(basename $(src))
181            romfsroot = $(TARGET.getImageDirectory false)/$(romfs_dir)
182            copiedfile = $(romfsroot)/$(filename)
183            copiedfiles += $(copiedfile)
184            $(copiedfile): $(src) $(makeDirectory $(romfsroot))
185                cp $(src) $(copiedfile)
186            export copiedfiles
187        export copiedfiles
188
189    return $(copiedfiles)
190
191# Open a file and load line by line.
192public.ReadFileLine(filename) =
193    f = $(fopen $(filename), r)
194    result =
195    while true
196        try
197            result += $(input-line $(f))
198            export result
199        catch RuntimeException(e)
200            break()
201            export result
202    close($(f))
203    return $(result)
204
205GetARM11Kernel(config) =
206    kernel = $(config.getSuitableKernelFilename)
207    kernel_arm11 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.)
208    return $(kernel_arm11)
209
210GetProcessList(config) =
211    return $(dirname $(GetARM11Kernel $(config)))$(DIRSEP)process.list
212
213GetARM9Kernel(config) =
214    kernel = $(config.getSuitableKernelFilename)
215    kernel_arm9 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.)
216
217    if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9)))
218        kernel_arm9 = $(gsub $(kernel_arm9),Development,Release)
219        kernel_arm9 = $(gsub $(kernel_arm9),Debug,Release)
220        export
221
222# Class to execute programs on the PC.
223HostProgramRunner. =
224    class HostProgramRunner
225
226    program =
227
228    new(program) =
229        this.program = $(program)
230        return $(this)
231
232    run() =
233        echo HostProgramRunner running ... $(program)
234        $(program) &
235
236public.MakeHostProgramRunner(program) =
237    return $(HostProgramRunner.new $(program))
238
239ProgramRunner. =
240    class ProgramRunner
241
242    new(program, exitpattern, timeout, depends) =
243        this.program = $(program)
244        this.exitPattern = $(exitpattern)
245        this.timeOut = $(timeout)
246        this.depends = $(depends)
247        return $(this)
248
249    GetDepends() =
250        if $(not $(SKIP_BUILD))
251            ret[] =
252                $(file $(program))
253                $(file $(depends))
254            return $(ret)
255        return $(EMPTY)
256
257    run(options, logfile) =
258        dependsoption =
259
260        foreach( depend, $(depends))
261            if $(not $(equal $(depend), ""))
262                dependsoption += -rp $(depend)
263                export dependsoption
264            export dependsoption
265
266        echo $(LOADRUN) $(options) $(dependsoption) -re $(program) -e $(exitPattern) -t $(timeOut) | tee $(logfile)
267        $(LOADRUN) $(options) $(dependsoption) -re $(program) -e $(exitPattern) -t $(timeOut) | tee $(logfile)
268
269public.MakeProgramRunnerWithDepends(program, exitpattern, timeout, deps) =
270    return $(ProgramRunner.new $(program),$(exitpattern),$(timeout), $(deps))
271
272public.MakeProgramRunner(program, exitpattern, timeout) =
273    return $(ProgramRunner.new $(program),$(exitpattern),$(timeout), "")
274
275public.GetToolPath(programName, ext) =
276    return $(HORIZON_ROOT_IMAGES)$(DIRSEP)tools$(DIRSEP)$(programName)$(DIRSEP)$`(TARGET.getFullnameWithSystem Process)$(DIRSEP)$`(TARGET.buildtype)$(DIRSEP)$(programName)$(ext)
277
278public.GetLocalProgramPath(programName) =
279    basedir = $(dirname $(absname $(programName)))
280    tmp_image_dir = $(dirname $(programName))
281    tmp_image_dir = $(absname $(addprefix $(basedir)$(DIRSEP)..$(DIRSEP)..$(DIRSEP),$(tmp_image_dir)))
282    tmp_image     = $(addsuffix $(EXT_CDI),$(basename $(proc)))
283    tmp_image     = $(addprefix $`(TARGET.getTargetSubDirectory false)$(DIRSEP),$(tmp_image))
284    processes += $(file $(addprefix $(tmp_image_dir)$(DIRSEP),$(tmp_image)))
285
286
287# Return the path of the CDI process for the specified name.
288public.GetProcessCdiPath(processName) =
289    return @$(GetProcessCdiPathPlain $(processName))
290
291# GetProcessCdiPath version to return path without @
292public.GetProcessCdiPathPlain(processName) =
293    if $(filter NuiShell TestMenu, $(processName))
294        return $(HORIZON_ROOT_IMAGES)$(DIRSEP)processes$(DIRSEP)CTR$(DIRSEP)$(processName)$(DIRSEP)$`(TARGET.getFullnameWithSystem Process)$(DIRSEP)$`(TARGET.buildtype)$(DIRSEP)$(processName).cdi
295    return $(HORIZON_ROOT_IMAGES)$(DIRSEP)processes$(DIRSEP)$(processName)$(DIRSEP)$`(TARGET.getFullnameWithSystem Process)$(DIRSEP)$`(TARGET.buildtype)$(DIRSEP)$(processName).cdi
296
297# Return the path of multiple specified CDI processes
298#
299# Example:
300#   DEPEND_PROCESSES[] =
301#       test_XXXX>$(GetProcessCdiPathList ptm cfg spi)
302#
303public.GetProcessCdiPathList(processNames) =
304    pathlist = $(GetProcessCdiPath $(nth 0, $(processNames)))
305    foreach(proc, $(nth-tl 1, $(processNames)))
306        pathlist =$(pathlist),$(GetProcessCdiPath $(proc))
307        export
308    return $(pathlist)
309
310public.GetLoadrunOptionsForTool() =
311    options =
312
313    if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT))
314        options += --no-wait
315        export options
316
317    return $(options)
318
319# Create objects to run programs with multiple targets.
320# Used with DefineMultiTargetTest.
321# TODO: Combined with the execution of other tests
322MakeMultiTargetRunner(program, depends, timeOut, previous) =
323    #program = $`(config.getBinaryPath $,(program), $(EXT_CCI))
324    return $(MultiTargetRunner.new $(program), $(depends), $(DEFAULT_EXIT_PATTERN), $(timeOut), $(previous))
325
326MultiTargetRunner. =
327    class MultiTargetRunner
328
329    new(runProgram, cdiDepends, exitPattern, timeOut, previous) =
330        this.runProgram = $(runProgram)
331        this.exitPattern = $(exitPattern)
332        this.cdiDepends = $(cdiDepends)
333        this.timeOut = $(timeOut)
334        this.previous = $(previous)
335        return $(this)
336
337    getOption(config) =
338        option =
339
340        option += -c0 esc -c0 init
341
342        # Kernel
343        option += -k11 $(GetARM11Kernel $(config))
344        option += -k9 $(GetARM9Kernel $(config))
345
346        # process.list
347        option += -pl $(GetProcessList $(config))
348
349        #Program
350        option +=
351            foreach( depend, $(cdiDepends) )
352                if $(equal $(suffix $(depend)), .cdi)
353                    value $(array -rp $(depend))
354                else
355                    value $(array -rid $(depend))
356
357        if $(equal $(suffix $(runProgram)), .cdi)
358            option += -rp $(runProgram)
359            export option
360        else
361            option += -re $(runProgram)
362            export option
363
364
365        # exitpattern, timeout
366        option += -t $(timeOut) -e $(exitPattern)
367
368        option += $(GetLoadrunOptionsForTool)
369
370        return $(option)
371
372    needLog() =
373        return true
374
375    getRunProgram() =
376        return $(runProgram)
377
378    getPrevious() =
379        return $(previous)
380
381    getDepends(config) =
382        depends =
383
384        if $(not $(and $(defined SKIP_BUILD),$(SKIP_BUILD)))
385            depends += $(array $(GetARM11Kernel $(config)) $(GetARM9Kernel $(config)) $(runProgram) $(cdiDepends))
386            export
387
388        return $(depends)
389
390    getLogfilePath(config) =
391        return $(addsuffix .multi.log, $(removesuffix $(runProgram)))
392
393# Define test execution rules for multiple targets.
394DefineMultiTargetTest(runners) =
395    BUILD_TESTS = true
396    if $(eq 0,$(length $(filter dotests-multi, $(TARGETS))))
397        return
398
399    foreach(TARGET, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
400        config = $(TARGET)
401        depends =
402            foreach( runner, $(runners) )
403                value $(runner.getDepends $(config))
404
405        outputs =
406            foreach( runner, $(runners) )
407                value $(runner.getLogfilePath $(config))
408
409        if $(not $(defined CTR_RUN_DEVICES))
410            eprintln(�����^�[�Qbg���g�����eXg�����s����ɂ� CTR_RUN_DEVICES �Ń^�[�Qbg���w�肵�Ă��������B)
411            exit(1)
412
413        num_runners = $(length $(runners))
414        devices = $(split $":", $(CTR_RUN_DEVICES))
415        num_devices = $(length $(devices))
416
417        if $(not $(le $(num_runners), $(num_devices)))
418            eprintln(���s�������v���O�����̐��ɑ΂��� CTR_RUN_DEVICES �ɐݒ肳��Ă���foCX�̐�������܂���B)
419            exit(1)
420
421        options =
422            foreach( runner, $(runners)  )
423                value $(quote-argv $(runner.getOption $(config)))
424
425        runPrograms =
426            foreach( runner, $(runners)  )
427                value $(quote-argv $(runner.getRunProgram))
428
429        previouses =
430            foreach( runner, $(runners)  )
431                value $(quote-argv $(runner.getPrevious))
432
433        logfiles =
434            foreach( runner, $(runners)  )
435                value $(runner.getLogfilePath $(config))
436
437        dotests-multi : $(logfiles)
438        $(logfiles): $(runPrograms) $(previouses) :effects: $(LOADRUN) :value: $(random)
439            section:
440               i = 0
441               while $(lt $i, $(num_runners))
442                   option = $(split $" ",$(nth $(i),$(options)))
443                   logfile = $(nth $(i),$(logfiles))
444                   device = $(nth $(i),$(devices))
445                   echo loadrunf $(option) -d $(device)
446                   $(LOADRUN) $,(option) -d $(device) | tee $(logfile) &
447                   sleep 3
448                   i = $(add $i, 1)
449
450CategoryParam. =
451    class CategoryParam
452
453    category            =   Normal
454    cannot_execution    =   false       # Cannot execute
455    system              =   false       # System
456    require_batch_update =  false       # Batch update required
457    not_require_user_approval = false   # User agreement not needed
458    not_require_right_for_mount = false # Rights not required to mount
459    can_skip_convert_jump_id = false    # Can skip JumpId conversion
460
461    descparam[]         =
462    makeromflags        =
463    ccflags             =
464
465    new(category, params) =
466        this.category       =   $(category)
467        foreach(param, $(params))
468            param_seq           =   $(split :, $(param))
469            paramname           =   $(nth 0, $(param_seq))
470            val                 =   true
471            if $(equal $(length $(param_seq)), 2)
472                val                 =   $(nth 1, $(param_seq))
473                export val
474
475            switch $(paramname)
476            case CannotExecution
477                this.cannot_execution = $(val)
478                export
479            case System
480                this.system = $(val)
481                export
482            case RequireBatchUpdate
483                this.require_batch_update = $(val)
484                export
485            case NotRequireUserApproval
486                this.not_require_user_approval = $(val)
487                export
488            case NotRequireRightForMount
489                this.not_require_right_for_mount = $(val)
490                export
491            case CanSkipConvertJumpId
492                this.can_skip_convert_jump_id = $(val)
493                export
494            default
495                echo $"[testutil.om CategoryParam] Undefined Parameter:" $(paramname)
496            export
497
498        this.descparam[]   +=
499                                CategoryFlags+=$(this.category)
500        this.makeromflags  +=   -DCATEGORYFLAGS0="- $(this.category)"
501        this.ccflags       +=   -DINFOVIEW_CATEGORY0=\"$(this.category)\"
502        idx                 =   1
503        if $(this.cannot_execution)
504            this.descparam[]   +=
505                                    CategoryFlags+=CannotExecution
506            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- CannotExecution"
507            this.ccflags       +=   -DINFOVIEW_CATEGORY1
508            idx                 =   $(add $(idx), 1)
509            export
510        if $(this.system)
511            this.descparam[]   +=
512                                    CategoryFlags+=System
513            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- System"
514            this.ccflags       +=   -DINFOVIEW_CATEGORY2
515            idx                 =   $(add $(idx), 1)
516            export
517        if $(this.require_batch_update)
518            this.descparam[]   +=
519                                    CategoryFlags+=RequireBatchUpdate
520            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- RequireBatchUpdate"
521            this.ccflags       +=   -DINFOVIEW_CATEGORY3
522            idx                 =   $(add $(idx), 1)
523            export
524        if $(this.not_require_user_approval)
525            this.descparam[]   +=
526                                    CategoryFlags+=NotRequireUserApproval
527            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- NotRequireUserApproval"
528            this.ccflags       +=   -DINFOVIEW_CATEGORY4
529            idx                 =   $(add $(idx), 1)
530            export
531        if $(this.not_require_right_for_mount)
532            this.descparam[]   +=
533                                    CategoryFlags+=NotRequireRightForMount
534            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- NotRequireRightForMount"
535            this.ccflags       +=   -DINFOVIEW_CATEGORY5
536            idx                 =   $(add $(idx), 1)
537            export
538        if $(this.can_skip_convert_jump_id)
539            this.descparam[]   +=
540                                    CategoryFlags+=CanSkipConvertJumpId
541            this.makeromflags  +=   -DCATEGORYFLAGS$(idx)=$"- CanSkipConvertJumpId"
542            this.ccflags       +=   -DINFOVIEW_CATEGORY6
543            idx                 =   $(add $(idx), 1)
544            export
545
546        return $(this)
547
548    isSystem() =
549        if $(this.system)
550            return true
551        return false
552
553    isContents() =
554        if $(equal $(this.category), Contents)
555            return true
556        return false
557
558    getDesc() =
559        desc                =   $(HORIZON_ROOT)/resources/specfiles/Application.desc
560        if $(equal $(this.category), DlpChild)
561            desc                =   $(HORIZON_ROOT)/resources/specfiles/DlpChild.desc
562            export desc
563        if $(equal $(this.category), Trial)
564            desc                =   $(HORIZON_ROOT)/resources/specfiles/Trial.desc
565            export desc
566        if $(this.isSystem)
567            desc                =   $(HORIZON_ROOT)/resources/specfiles/_private/SystemTest.desc
568            export desc
569        return $(desc)
570
571# Create category to specify in MakeDummyCia.
572public.MakeCategoryParam(category, params) =
573    return $(CategoryParam.new $(category), $(params))
574
575# Generate dummy content.
576public.MakeDummyContents(name, category, unique_id, contents_dir, numcontents, data_size) =
577    contents[]          =
578    testutil_dir        =   $(ROOT_SOURCES)/libraries/test/util
579    idx_cfa             =   0
580    while $(lt $(idx_cfa), $(numcontents))
581        section
582            MAKEROMFLAGS       +=   -DUNIQUE_ID=$(unique_id)
583            if $(category.isSystem)
584                MAKEROMFLAGS       +=   -keyfile $(GetSystemFixedKeyFile)
585                export MAKEROMFLAGS
586            if $(category.isContents)
587                MAKEROMFLAGS       +=   -DCONTENTSINDEX=$(idx_cfa)
588                export MAKEROMFLAGS
589            else
590                MAKEROMFLAGS       +=   -DCONTENTSINDEX=0
591                export MAKEROMFLAGS
592            MAKEROMFLAGS       +=   $(category.makeromflags)
593
594            cfa_name            =   content_$(idx_cfa)
595            cfa_dir             =   $(contents_dir)/$(name)/cfafiles
596            cfa_file            =   $(cfa_dir)/$(cfa_name)$(EXT_CFA)
597            data_file           =   $(MakeSpecifiedSizeFile $(contents_dir)/$(name)/$(cfa_name)/data.txt, $(data_size))
598
599            $(cfa_file): $(data_file)
600            contents           +=   $(FileArchiveWithOutdir $(dirname $(data_file)), $(cfa_dir), $(testutil_dir)/dummycontent.rsf)
601            idx_cfa             =   $(add $(idx_cfa), 1)
602            export contents idx_cfa
603    return $(contents)
604
605# Generate dummy title.
606public.MakeDummyCia(tar, name, category, unique_id, variation, major_version, minor_version, micro_version, numcontents, titlesize, save_data_size) =
607    cia_file            =
608
609    if $(equal $(tar), CTR)
610        cia_file            =   $(MakeDummyCiaCtr $(name), $(category), $(unique_id), $(variation), $(major_version), $(minor_version), $(micro_version), $(numcontents), $(titlesize), $(save_data_size))
611        export cia_file
612
613    if $(equal $(tar), TWL)
614        cia_file            =   $(MakeDummyCiaTwl $(name), $(category), $(unique_id), $(variation), $(major_version), $(minor_version), $(micro_version), $(numcontents), $(titlesize), $(save_data_size))
615        export cia_file
616
617    return $(cia_file)
618
619# Generate dummy title for CTR.
620public.MakeDummyCiaCtr(name, category, unique_id, variation, major_version, minor_version, micro_version, numcontents, titlesize, save_data_size) =
621    objects_dir         =   $(getOutputBaseDirectory)/$(SUBDIR_OBJECTS)/$(getModuleSubDirectory)
622    testutil_dir        =   $(ROOT_SOURCES)/libraries/test/util
623    cia_files           =
624
625    # Create content.
626    contents            =
627    if $(gt $(numcontents), 0)
628        data_size           =   $(div $(titlesize) $(numcontents))
629        contents            =   $(MakeDummyContents $(name), $(category), $(unique_id), $(objects_dir), $(numcontents), $(data_size))
630        export contents
631
632    foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
633        cia_file            =   $(target.getImageDirectory false)/$(name)$(EXT_CIA)
634        infoviewer_cxi      =
635        if $(not $(category.isContents))
636            # Create test program (for parameter display).
637            infoviewer_name     =   InfoViewer_$(name)
638            infoviewer_cxi      =   $(target.getImageDirectory false)/$(infoviewer_name)$(EXT_CXI)
639
640            srccppfile          =   $(testutil_dir)/InfoViewer.cpp
641            copycpp             =   $(target.getObjectDirectory)/$(infoviewer_name).cpp
642            $(copycpp): $(srccppfile) $(makeDirectory $(dirname $(copycpp)))
643                cp $(srccppfile) $(copycpp)
644
645            sources[]           =
646                                    $(copycpp)
647            LIBS               +=   libnn_demoLite
648
649            target_program      =   $(infoviewer_name)
650            TITLE               =   $(infoviewer_name)
651            ROM_SPEC_FILE       =   $(testutil_dir)/dummyaxf.rsf
652            ROMFS_DEPENDENCIES  =
653            ROMFS_ROOT          =
654            MAKEROMFLAGS       +=   -DUNIQUE_ID=$(unique_id) \
655                                    -DSAVEDATASIZE=$(save_data_size) \
656                                    -DREMASTERVERSION=$(major_version)
657
658            CCFLAGS            +=   -DINFOVIEW_FILENAME=\"$(basename $(cia_file))\" \
659                                    -DINFOVIEW_UNIQUE_ID=\"$(unique_id)\" \
660                                    -DINFOVIEW_TITLESIZE=\"$(titlesize)\" \
661                                    -DINFOVIEW_SAVEDATASIZE=\"$(save_data_size)\" \
662                                    -DINFOVIEW_NUMCONTENTS=\"$(numcontents)\" \
663                                    -DINFOVIEW_VARIATION=\"$(variation)\" \
664                                    -DINFOVIEW_REMASTERVERSION=\"$(major_version)\" \
665                                    -DINFOVIEW_TMDVERSION=\"$(major_version).$(minor_version).$(micro_version)\" \
666                                    $(category.ccflags)
667
668            DESCRIPTOR          =   $(category.getDesc)
669            DESC_PARAM[]        =
670                                    $(category.descparam)
671            MAKEROMFLAGS       +=   $(category.makeromflags)
672            if $(equal $(category.category), DlpChild)
673                MAKEROMFLAGS       +=   -DVERSION=0 \
674                                        -DCHILDINDEX=$(variation)
675                export MAKEROMFLAGS
676            else
677                MAKEROMFLAGS       +=   -DVERSION=$(variation) \
678                                        -DCHILDINDEX=0
679                export MAKEROMFLAGS
680
681            if $(defined UserRunProcess)
682                infoviewer_files = $(UserRunProcess $(target), $(target_program), $(sources))
683            else
684                infoviewer_files = $(UserProcess $(target), $(target_program), $(sources))
685
686            export infoviewer_cxi
687
688        # Generate CIA.
689        makeciaflags        =
690        content_files       =
691        idx                 =   0
692        if $(infoviewer_cxi)
693            makeciaflags       +=   -i $(join $(infoviewer_cxi), :$(idx))
694            content_files      +=   $(infoviewer_cxi)
695            idx = $(add $(idx), 1)
696            export makeciaflags content_files idx
697
698        foreach(content, $(contents))
699            makeciaflags       +=   -i $(join $(content), :$(idx))
700            content_files      +=   $(content)
701            idx = $(add $(idx), 1)
702            export makeciaflags content_files idx
703
704        makeciaflags       +=   -minor $(minor_version) -micro $(micro_version)
705        if $(category.isSystem)
706            makeciaflags       +=   -cxikey $(GetSystemFixedKeyFile)
707            export makeciaflags
708        if $(category.isContents)
709            makeciaflags       +=   -major $(major_version)
710            export makeciaflags
711
712        $(cia_file): $(content_files) $(makeDirectory $(dirname $(cia_file))) $(MAKECIA)
713            $(MAKECIA) -o $@ $(makeciaflags)
714
715        cia_files          +=   $(cia_file)
716
717        export cia_files
718
719    return $(cia_files)
720
721# Generate dummy title for TWL.
722public.MakeDummyCiaTwl(name, category, unique_id, variation, major_version, minor_version, micro_version, numcontents, titlesize, save_data_size) =
723    objects_dir         =   $(getOutputBaseDirectory)/$(SUBDIR_OBJECTS)/$(getModuleSubDirectory)
724    cia_files           =
725
726    # Create dummy file for TWL.
727    twl_data            =   $(objects_dir)/twl/twldata.dat
728    if $(not $(file-exists $(twl_data)))
729        twl_data            =   $(MakeSpecifiedSizeFile $(twl_data), 1024)
730
731    foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
732        # Generate title.
733        cia_file            =   $(target.getImageDirectory false)/$(name)$(EXT_CIA)
734        content_files       =   $(twl_data)
735        makeciaflags        =   -major $(major_version) \
736                                -minor $(minor_version) \
737                                -micro $(micro_version) \
738                                -p $(unique_id) \
739                                -padding
740
741        $(cia_file): $(content_files) $(makeDirectory $(dirname $(cia_file))) $(MAKECIA)
742            $(MAKECIA) -a $(content_files) -o $@ $(makeciaflags)
743
744        cia_files          +=   $(cia_file)
745
746        export cia_files
747
748    return $(cia_files)
749
750
751# =======================================================================
752#
753#  MakeDummyCiaEx
754#
755#    MakeDummyCia has too many arguments and is hard to use, so added a version that takes MakeDummyCiaOption object as the argument.
756#
757#
758#    By using option objects, because named options can be used, it is easy to know what was set when you are later reviewing the code.
759#
760#
761#    Also, by defining an Option class to be used for specific applications in advance, it is hoped that a dedicated CIA can be created with comparatively shorter code.
762#
763#
764# =======================================================================
765
766# -----------------------------------------------------------------------
767# MakeDummyCiaOption
768# -----------------------------------------------------------------------
769MakeDummyCiaOption. =
770    class MakeDummyCiaOption
771
772    target              = CTR
773    category            = $(MakeCategoryParam Normal, $(EMPTY))
774    unique_id           = 0xFE000
775    variation           = 0
776    major_version       = 1
777    minor_version       = 0
778    micro_version       = 0
779    numcontents         = 0
780    titlesize           = 128
781    save_data_size      = 0K
782
783    makeciaflags        =
784
785    content_ids         =
786
787    new() =
788        return $(this)
789
790# Generate dummy title.
791public.MakeDummyCiaEx(name, options) =
792    cia_file            =
793
794    if $(equal $(options.target), CTR)
795        cia_file            =   $(MakeDummyCiaCtrWithOption $(name), $(options))
796        export cia_file
797    else
798        eprintln()
799        exit(1)
800
801    return $(cia_file)
802
803# Generate dummy title for CTR.
804public.MakeDummyCiaCtrWithOption(name, options) =
805    #variation, major_version, minor_version, micro_version, numcontents, titlesize, save_data_size
806    objects_dir         =   $(getOutputBaseDirectory)/$(SUBDIR_OBJECTS)/$(getModuleSubDirectory)
807    testutil_dir        =   $(ROOT_SOURCES)/libraries/test/util
808    cia_files           =
809    category            =   $(options.category)
810    unique_id           =   $(options.unique_id)
811    variation           =   $(options.variation)
812    major_version       =   $(options.major_version)
813    minor_version       =   $(options.minor_version)
814    micro_version       =   $(options.micro_version)
815    numcontents         =   $(options.numcontents)
816    titlesize           =   $(options.titlesize)
817    save_data_size      =   $(options.save_data_size)
818
819    # Create content.
820    contents            =
821    if $(gt $(numcontents), 0)
822        data_size           =   $(div $(titlesize) $(numcontents))
823        contents            =   $(MakeDummyContents $(name), $(category), $(unique_id), $(objects_dir), $(numcontents), $(data_size))
824        export contents
825
826    foreach(target, $(BUILDER.getTargets $(SUPPORTED_TARGETS)))
827        cia_file            =   $(target.getImageDirectory false)/$(name)$(EXT_CIA)
828        infoviewer_cxi      =
829        if $(not $(category.isContents))
830            # Create test program (for parameter display).
831            infoviewer_name     =   InfoViewer_$(name)
832            infoviewer_cxi      =   $(target.getImageDirectory false)/$(infoviewer_name)$(EXT_CXI)
833
834            srccppfile          =   $(testutil_dir)/InfoViewer.cpp
835            copycpp             =   $(target.getObjectDirectory)/$(infoviewer_name).cpp
836            $(copycpp): $(srccppfile) $(makeDirectory $(dirname $(copycpp)))
837                cp $(srccppfile) $(copycpp)
838
839            sources[]           =
840                                    $(copycpp)
841            LIBS               +=   libnn_demoLite
842
843            target_program      =   $(infoviewer_name)
844            TITLE               =   $(infoviewer_name)
845            ROM_SPEC_FILE       =   $(testutil_dir)/dummyaxf.rsf
846            ROMFS_DEPENDENCIES  =
847            ROMFS_ROOT          =
848            MAKEROMFLAGS       +=   -DUNIQUE_ID=$(unique_id) \
849                                    -DSAVEDATASIZE=$(save_data_size) \
850                                    -DREMASTERVERSION=$(major_version)
851
852            CCFLAGS            +=   -DINFOVIEW_FILENAME=\"$(basename $(cia_file))\" \
853                                    -DINFOVIEW_UNIQUE_ID=\"$(unique_id)\" \
854                                    -DINFOVIEW_TITLESIZE=\"$(titlesize)\" \
855                                    -DINFOVIEW_SAVEDATASIZE=\"$(save_data_size)\" \
856                                    -DINFOVIEW_NUMCONTENTS=\"$(numcontents)\" \
857                                    -DINFOVIEW_VARIATION=\"$(variation)\" \
858                                    -DINFOVIEW_REMASTERVERSION=\"$(major_version)\" \
859                                    -DINFOVIEW_TMDVERSION=\"$(major_version).$(minor_version).$(micro_version)\" \
860                                    $(category.ccflags)
861
862            DESCRIPTOR          =   $(category.getDesc)
863            DESC_PARAM[]        =
864                                    $(category.descparam)
865            MAKEROMFLAGS       +=   $(category.makeromflags)
866            if $(equal $(category.category), DlpChild)
867                MAKEROMFLAGS       +=   -DVERSION=0 \
868                                        -DCHILDINDEX=$(variation)
869                export MAKEROMFLAGS
870            else
871                MAKEROMFLAGS       +=   -DVERSION=$(variation) \
872                                        -DCHILDINDEX=0
873                export MAKEROMFLAGS
874
875            if $(defined UserRunProcess)
876                infoviewer_files = $(UserRunProcess $(target), $(target_program), $(sources))
877            else
878                infoviewer_files = $(UserProcess $(target), $(target_program), $(sources))
879
880            export infoviewer_cxi
881
882        # Generate CIA.
883        makeciaflags        =   $(options.makeciaflags)
884        content_files       =
885        idx                 =   0
886        if $(infoviewer_cxi)
887            if $(options.content_ids)
888                makeciaflags       +=   -i $(join $(infoviewer_cxi), :$(idx):$(nth $(idx), $(options.content_ids)))
889                export
890            else
891                makeciaflags       +=   -i $(join $(infoviewer_cxi), :$(idx))
892                export
893            content_files      +=   $(infoviewer_cxi)
894            idx = $(add $(idx), 1)
895            export makeciaflags content_files idx
896
897        foreach(content, $(contents))
898            if $(options.content_ids)
899                makeciaflags       +=   -i $(join $(content), :$(idx):$(nth $(idx), $(options.content_ids)))
900                export
901            else
902                makeciaflags       +=   -i $(join $(content), :$(idx))
903                export
904            content_files      +=   $(content)
905            idx = $(add $(idx), 1)
906            export makeciaflags content_files idx
907
908        makeciaflags       +=   -minor $(minor_version) -micro $(micro_version)
909        if $(category.isSystem)
910            makeciaflags       +=   -cxikey $(GetSystemFixedKeyFile)
911            export makeciaflags
912        if $(category.isContents)
913            makeciaflags       +=   -major $(major_version)
914            export makeciaflags
915
916        $(cia_file): $(content_files) $(makeDirectory $(dirname $(cia_file))) $(MAKECIA)
917            $(MAKECIA) -o $@ $(makeciaflags)
918
919        cia_files          +=   $(cia_file)
920
921        export cia_files
922
923    return $(cia_files)
924
925