aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain-Test/build.gradle
blob: f621428edb65cd9f1d25ba18d475d8981fcd9fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        // NOTE: Always use fixed version codes not dynamic ones, e.g. 0.7.3 instead of 0.7.+, see README for more information
        classpath 'com.novoda:gradle-android-test-plugin:0.10.0'
    }
}

apply plugin: 'java'
apply plugin: 'android-test'
apply plugin: 'jacoco'

dependencies {
    testCompile 'junit:junit:4.11'
    testCompile 'com.google.android:android:4.1.1.4'
    testCompile('com.squareup:fest-android:1.0.+') { exclude module: 'support-v4' }
    testCompile ('org.robolectric:robolectric:2.3') {
        exclude module: 'classworlds'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-plugin-registry'
        exclude module: 'maven-profile'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'nekohtml'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'support-v4' // crazy but my android studio don't like this dependency and to fix it remove .idea and re import project
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-http-shared'
        exclude module: 'wagon-provider-api'
    }
}

test {
    exclude '**/*$*'
}

android {
    projectUnderTest ':OpenKeychain'
}

jacoco {
    toolVersion = "0.7.2.201409121644"
}


def coverageSourceDirs = [
        '../OpenKeychain/src/main/java',
        '../OpenKeychain/src/gen',
        '../OpenKeychain/build/source/apt/debug',
        '../OpenKeychain/build/source/generated/buildConfig/debug',
        '../OpenKeychain/build/source/generated/r/debug'
    ]

jacocoTestReport {
    reports {
        xml.enabled = true
        html.destination "${buildDir}/jacocoHtml"
    }
    // class R is used, but usage will not be covered, so ignore this class from report
    classDirectories = fileTree(dir: '../OpenKeychain/build/intermediates/classes/debug/org/sufficientlysecure/keychain', exclude: [ 'R*.class' ])
    additionalSourceDirs = files(coverageSourceDirs)
    executionData = files('build/jacoco/testDebug.exec')
}

// new workaround to force add custom output dirs for android studio
task addTest {
    def file = file(project.name + ".iml")
    doLast {
        try {
            def parsedXml = (new XmlParser()).parse(file)
            def node = parsedXml.component[1]
            def outputNode = parsedXml.component[1].output[0]
            def outputTestNode = parsedXml.component[1].'output-test'[0]
            def rewrite = false

            new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])

            if(outputNode == null) {
                new Node(node, 'output', ['url': 'file://$MODULE_DIR$/build/resources/testDebug'])
            } else {
                if(outputNode.attributes['url'] != 'file://$MODULE_DIR$/build/resources/testDebug') {
                    outputNode.attributes = ['url': 'file://$MODULE_DIR$/build/resources/testDebug']
                    rewrite = true
                }
            }

            if(outputTestNode == null) {
                new Node(node, 'output-test', ['url': 'file://$MODULE_DIR$/build/test-classes/debug'])
            } else {
                if(outputTestNode.attributes['url'] != 'file://$MODULE_DIR$/build/test-classes/debug') {
                    outputTestNode.attributes = ['url': 'file://$MODULE_DIR$/build/test-classes/debug']
                    rewrite = true
                }
            }

            if(rewrite) {
                def writer = new StringWriter()
                new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
                file.text = writer.toString()
            }
        } catch (FileNotFoundException e) {
            // iml not found, common on command line only builds
        }

    }
}

// always do the addtest on prebuild
gradle.projectsEvaluated {
    testDebugClasses.dependsOn(addTest)
}
lass="cp">} #define DO_ERROR_INFO(trapnr, str, name, sicode, siaddr) \ void do_##name(struct pt_regs * regs, unsigned long error_code) \ { \ do_trap(trapnr, str, regs, error_code); \ } DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip) DO_ERROR( 3, "int3", int3) DO_ERROR( 4, "overflow", overflow) DO_ERROR( 5, "bounds", bounds) DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip) DO_ERROR( 7, "device not available", device_not_available) DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun) DO_ERROR(10, "invalid TSS", invalid_TSS) DO_ERROR(11, "segment not present", segment_not_present) DO_ERROR(12, "stack segment", stack_segment) DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0) DO_ERROR(18, "machine check", machine_check) void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long addr) { printk("Page fault at linear address %p\n", addr); dump_regs(regs); #ifdef __x86_64__ { unsigned long *tab = (unsigned long *)start_info.pt_base; unsigned long page; printk("Pagetable walk from %p:\n", tab); page = tab[l4_table_offset(addr)]; tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT); printk(" L4 = %p (%p)\n", page, tab); if ( !(page & AGERESENT) ) goto out; page = tab[l3_table_offset(addr)]; tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT); printk(" L3 = %p (%p)\n", page, tab); if ( !(page & AGERESENT) ) goto out; page = tab[l2_table_offset(addr)]; tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT); printk(" L2 = %p (%p) %s\n", page, tab, (page & AGESE) ? "(2MB)" : ""); if ( !(page & AGERESENT) || (page & AGESE) ) goto out; page = tab[l1_table_offset(addr)]; printk(" L1 = %p\n", page); } #endif do_exit(); } void do_general_protection(struct pt_regs *regs, long error_code) { printk("GPF %p, error_code=%lx\n", regs, error_code); dump_regs(regs); do_exit(); } void do_debug(struct pt_regs * regs) { printk("Debug exception\n"); #define TF_MASK 0x100 regs->eflags &= ~TF_MASK; dump_regs(regs); do_exit(); } void do_coprocessor_error(struct pt_regs * regs) { printk("Copro error\n"); dump_regs(regs); do_exit(); } void simd_math_error(void *eip) { printk("SIMD error\n"); } void do_simd_coprocessor_error(struct pt_regs * regs) { printk("SIMD copro error\n"); } void do_spurious_interrupt_bug(struct pt_regs * regs) { } /* * Submit a virtual IDT to teh hypervisor. This consists of tuples * (interrupt vector, privilege ring, CS:EIP of handler). * The 'privilege ring' field specifies the least-privileged ring that * can trap to that vector using a software-interrupt instruction (INT). */ static trap_info_t trap_table[] = { { 0, 0, __KERNEL_CS, (unsigned long)divide_error }, { 1, 0, __KERNEL_CS, (unsigned long)debug }, { 3, 3, __KERNEL_CS, (unsigned long)int3 }, { 4, 3, __KERNEL_CS, (unsigned long)overflow }, { 5, 3, __KERNEL_CS, (unsigned long)bounds }, { 6, 0, __KERNEL_CS, (unsigned long)invalid_op }, { 7, 0, __KERNEL_CS, (unsigned long)device_not_available }, { 9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun }, { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS }, { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present }, { 12, 0, __KERNEL_CS, (unsigned long)stack_segment }, { 13, 0, __KERNEL_CS, (unsigned long)general_protection }, { 14, 0, __KERNEL_CS, (unsigned long)page_fault }, { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug }, { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error }, { 17, 0, __KERNEL_CS, (unsigned long)alignment_check }, { 18, 0, __KERNEL_CS, (unsigned long)machine_check }, { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error }, { 0, 0, 0, 0 } }; void trap_init(void) { HYPERVISOR_set_trap_table(trap_table); }