Sunday, May 13, 2012

Generating ReportNG, Testng-xslt reports for TestNG based Selenium tests cases

- no title specified

This guide is based off a Windows 7 Home Premium 64 bit box.

PDF Version


The PDF version is much better than this blog write up.

About this guide

We use Selenium Android Webdriver using remote server architecture in this guide (see http://code.google.com/p/selenium/wiki/AndroidDriver#Setup_the_Environment). All code is in Java. This guide assumes that you have only one Android device connected to your box.

This guide is a quick start for the following:

  1. 1.Write a Selenium test case using Eclipse IDE 
  2. 2.Wrap Selenium test case in TestNG using Eclipse IDE. 
  3. 3.Generate ReportNG based report for the test run using Eclipse IDE. 
  4. 4.Generate testng-xslt based report for the test run using ANT. 

Prerequisites

  1. 1.JDK. 
  2. 2.Working Eclipse IDE. 
  3. 3.Android Debug Bridge (ADB). 
  4. 4.An Android target that can be reached from the Windows box. 
  5. 5.Basics on Selenium, TestNG, ReportNG, testng-xslt, Android. 

Optional

  1. 1.7 Zip command line 

Versions

Product
Version number
Eclipse

Java
C:\>java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
ADB
C:\>adb version
Android Debug Bridge version 1.0.29
7 Zip Command line
C:\>7za

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

Setup working directory

C:\>md SeleniumTestNg
C:\>cd SeleniumTestNg

Download Selenium Jars

C:\SeleniumTestNg>md Selenium

Download files listed below from http://seleniumhq.org/download/ into the above created Selenium directory.

Selenium server for Android devices
Selenium Java client driver

Post download, you should be seeing this:

C:\SeleniumTestNg>dir /s
 Volume in drive C has no label.
 Volume Serial Number is 668E-84EF

 Directory of C:\SeleniumTestNg

05/13/2012  11:43 AM    <DIR>          .
05/13/2012  11:43 AM    <DIR>          ..
05/13/2012  11:44 AM    <DIR>          Selenium
               0 File(s)              0 bytes

 Directory of C:\SeleniumTestNg\Selenium

05/13/2012  11:44 AM    <DIR>          .
05/13/2012  11:44 AM    <DIR>          ..
05/13/2012  11:44 AM         1,881,490 android-server-2.21.0.apk
05/13/2012  11:44 AM        21,387,046 selenium-java-2.21.0.zip
               2 File(s)     23,268,536 bytes

     Total Files Listed:
               2 File(s)     23,268,536 bytes
               5 Dir(s)  427,898,490,880 bytes free

Setup Selenium Android server on your Android device

Connect your Android device to Windows box and ensure connectivity. Run below commands. The serial number passed onto “adb -s” must be your device serial.

C:\SeleniumTestNg>cd Selenium

C:\SeleniumTestNg\Selenium>adb install android-server-2.21.0.apk
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
2639 KB/s (1881490 bytes in 0.696s)
        pkg: /data/local/tmp/android-server-2.21.0.apk
Success

C:\SeleniumTestNg\Selenium>adb devices
List of devices attached
5a03cd22        device

C:\SeleniumTestNg\Selenium>adb -s 5a03cd22 forward tcp:8080 tcp:8080

Selenium test case in Eclipse IDE

C:\SeleniumTestNg\Eclipse will be our eclipse project directory.

C:\SeleniumTestNg>md Eclipse

Extract Selenium jars.

C:\SeleniumTestNg>cd Selenium
C:\SeleniumTestNg\Selenium>7za x selenium-java-2.21.0.zip

Create an Eclipse Java project. Click Finish.


 Add a new java class.



Add Selenium jars to project

  1. 1.Add everything in C:\SeleniumTestNg\Selenium\selenium-2.21.0\selenium-2.21.0\libs 
  2. 2.Add C:\SeleniumTestNg\Selenium\selenium-2.21.0\selenium-2.21.0\selenium-java-2.21.0.jar 















After adding Jars, your Libraries tab should look like below. The black line represents scroll continuity.



















Add code.


package com.selenium.test;

import junit.framework.TestCase;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;

public class MyTest extends TestCase {

  public void testGoogle() throws Exception {
    WebDriver driver = new AndroidDriver();
    driver.get("http://www.google.com");
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Cheese!");
    element.submit();
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
  }
}

Start Webdriver on device. You can do this by clicking on the WebDriver icon in your Android device launcher or thru command line.

C:\SeleniumTestNg>adb shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity -e debug true
Starting: Intent { act=android.intent.action.MAIN cmp=org.openqa.selenium.android.app/.MainActivity (has extras) }

Run test.





If everything went well, test results should be displayed.


Install TestNG plugin for Eclipse




























Accept all warnings, complete the installation of TestNG plug-in and restart Eclipse.
  
Verify TestNG was installed




















If TestNG installation was successful, TestNG tab should show up.




Selenium test cases with TestNG

We will add our Test cases in the same project. We will also add a dummy test case that simulates failure.

























































This is our TestNG wrapped Selenium test case. Contents of MyTestNG.java.

package com.selenium.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
import org.testng.ITestContext;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class MyTestNG {
  @Test(description="Launches the google webpage")
  public void launchGoogle() {
     WebDriver driver = new AndroidDriver();
     driver.get("http://www.google.com");
     WebElement element = driver.findElement(By.name("q"));
     element.sendKeys("Cheese!");
     element.submit();
     System.out.println("Page title is: " + driver.getTitle());
     driver.quit();
  }

  @Test(description="Simulates a failed test case")
  public void failedTestCase() {
     org.testng.Assert.fail("This test case failed ...");
  }
 
  @BeforeSuite(alwaysRun = true)
  public void setupBeforeSuite(ITestContext context) {
  }
   
  @AfterSuite(alwaysRun = true)
  public void setupAfterSuite() {
  }
 
}



Running TestNG wrapped Selenium test cases




Test results are displayed. Remember that we simulated a test case to fail.




Refresh the eclipse project after run.

The test run report (test-output directory) has been added to the project directory. Double click and open index.html.





ReportNG setup

C:\SeleniumTestNg>md ReportNG

Download ReportNG files from https://github.com/dwdyer/reportng/downloads to C:\SeleniumTestNg\ReportNG. Direct URLs of files is below.


Post download, you should have below files.

C:\SeleniumTestNg\ReportNG>dir
 Volume in drive C has no label.
 Volume Serial Number is 668E-84EF

 Directory of C:\SeleniumTestNg\ReportNG

05/13/2012  02:43 PM    <DIR>          .
05/13/2012  02:43 PM    <DIR>          ..
05/13/2012  02:43 PM         5,721,067 dwdyer-reportng-Release-1.1.3-5-gef5f582.zip
05/13/2012  02:43 PM           510,413 reportng-1.1.3.tgz
               2 File(s)      6,231,480 bytes
               2 Dir(s)  427,899,600,896 bytes free



Extract files.

C:\SeleniumTestNg\ReportNG>7za x dwdyer-reportng-Release-1.1.3-5-gef5f582.zip
C:\SeleniumTestNg\ReportNG>7za x reportng-1.1.3.tgz
C:\SeleniumTestNg\ReportNG>7za x reportng-1.1.3.tar

ReportNG jars must be added to our project. This process is similar to the way we added Selenium jars.

Below is the list of ReportNG jars that must be added:

  1. 1.C:\SeleniumTestNg\ReportNG\reportng-1.1.3\reportng-1.1.3.jar 
  2. 2.C:\SeleniumTestNg\ReportNG\dwdyer-reportng-ef5f582\lib\compiletime\testng\guice-3.0.jar 


ReportNG reports

Add ReportNG as a TestNG suite listener. This is done by adding the listener tag to MyTestNG.xml. Below is the modified MyTestNG.xml. Highlighted code is the newly added listener.


<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
  <listeners>
      <listener class-name="org.uncommons.reportng.HTMLReporter"/>
  </listeners>    
  <test name="Test">
    <classes>
      <class name="com.selenium.test.MyTestNG"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->


Re-run the TestNG suite. See “Running TestNG wrapped Selenium test cases”. After run, Refresh(F5) the project. The results are generated in test-output\html directory.








ANT setup

ANT is needed to generate testng-xslt reports. We will be installing and using ANT locally from our SeleniumTestNg directory.

C:\SeleniumTestNg>mkdir ANT

Download a Windows binary version of ANT. There are a bunch of mirrors. Direct URL to download from fightrice mirror is http://www.fightrice.com/mirrors/apache//ant/binaries/apache-ant-1.8.3-bin.zip

Post download, you should be seeing this.

C:\SeleniumTestNg\ANT>dir
 Volume in drive C has no label.
 Volume Serial Number is 668E-84EF

 Directory of C:\SeleniumTestNg\ANT

05/13/2012  03:24 PM    <DIR>          .
05/13/2012  03:24 PM    <DIR>          ..
05/13/2012  03:24 PM         8,093,329 apache-ant-1.8.3-bin.zip
               1 File(s)      8,093,329 bytes
               2 Dir(s)  427,878,535,168 bytes free


Unzip ANT.

C:\SeleniumTestNg\ANT>7za x apache-ant-1.8.3-bin.zip


Testng-xslt setup

We will be using the standalone version of testng-xslt and not the maven plugin. Create a directory for testng-xslt.

C:\SeleniumTestNg>mkdir testng-xslt

Download testng-xslt and save it to the above directory. Direct download URL is http://testng-xslt.googlecode.com/files/testng-xslt-1.1.1.zip

Post download, you should see the below.

C:\SeleniumTestNg\testng-xslt>dir
 Volume in drive C has no label.
 Volume Serial Number is 668E-84EF

 Directory of C:\SeleniumTestNg\testng-xslt

05/13/2012  03:33 PM    <DIR>          .
05/13/2012  03:33 PM    <DIR>          ..
05/13/2012  03:33 PM         2,221,297 testng-xslt-1.1.1.zip
               1 File(s)      2,221,297 bytes
               2 Dir(s)  427,834,396,672 bytes free

Unzip testng-xslt.

C:\SeleniumTestNg\testng-xslt>7za x testng-xslt-1.1.1.zip

Set JAVA_HOME. There should not be Quotes enclosing the JAVA_HOME path. Ant.bat will re-use JAVA_HOME internally. Any Quotes in JAVA_HOME will cause parse errors when running Ant.bat.

C:\SeleniumTestNg\testng-xslt>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_03

Testng-xslt report

To generate a testng-xslt report, you need testng-results.xml. After a “TestNG” run, it is generated in the Eclipse project's test-output directory. Copy that file into testng-xslt\test directory.

C:\SeleniumTestNg>copy Eclipse\test-output\testng-results.xml testng-xslt\test
        1 file(s) copied.

Ensure that JAVA_HOME is set on this console. Generate the report by running Ant.

C:\SeleniumTestNg\testng-xslt>c:\SeleniumTestNg\ANT\apache-ant-1.8.3\bin\ant tes
tcase
Buildfile: C:\SeleniumTestNg\testng-xslt\build.xml

testcase:
    [mkdir] Created dir: C:\SeleniumTestNg\testng-xslt\test\output
     [xslt] Processing C:\SeleniumTestNg\testng-xslt\test\testng-results.xml to
C:\SeleniumTestNg\testng-xslt\test\output\index.html
     [xslt] Loading stylesheet C:\SeleniumTestNg\testng-xslt\src\main\resources\
testng-results.xsl

BUILD SUCCESSFUL
Total time: 1 second

Testng-xstl HTML report output is generated in C:\SeleniumTestNg\testng-xslt\test\output. Open index.html from this directory.

C:\SeleniumTestNg\testng-xslt>start C:\SeleniumTestNg\testng-xslt\test\output\index.html


Screenshot of testng-xstl report.





ANT processing errors

Got yourself a bunch of errors like the below?


Buildfile: C:\SeleniumTestNg\TestNG\build.xml

[xslt] : Error! Syntax error in 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 23: Error parsing XPath expression 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 23: Required attribute 'select' is missing.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 12: The method attribute of an <xsl:output> element had the value 'xhtml'.  The value must be one of 'xml', 'html', 'text', or qname-but-not-ncname

[xslt] : Error! Syntax error in 'if (suite/@url) then document(suite/@url)/suite else suite'.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 421: Error parsing XPath expression 'if (suite/@url) then document(suite/@url)/suite else suite'.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 421: Required attribute 'select' is missing.

[xslt] : Error! Syntax error in 'if (test/@url) then document(test/@url)/test else test'.
[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 690: Error parsing XPath expression 'if (test/@url) then document(test/@url)/test else test'.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 690: Required attribute 'select' is missing.

[xslt] : Error! Syntax error in 'if (compare($sortByStartTime, 'true') = 0) then @started-at else '''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 892: Error parsing XPath expression 'if (compare($sortByStartTime, 'true') = 0) then @started-at else '''.

[xslt] : Error! Syntax error in 'if (compare($testNgXslt.sortTestCaseLinks, 'true') = 0) then @name else '''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 1003: Error parsing XPath expression 'if (compare($testNgXslt.sortTestCaseLinks, 'true') = 0) then @name else '''.

[xslt] : Error! Syntax error in 'null'.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 1010: Error parsing XPath expression 'null'.

[xslt] : Error! Syntax error in 'if ($totalCount > 0) then format-number($passedCount div $totalCount, '###%') else '100%''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 1085: Error parsing XPath expression 'if ($totalCount > 0) then format-number($passedCount div $totalCount, '###%') else '100%''.

[xslt] : Error! file:/C:/SeleniumTestNg/TestNG/testng-results.xsl: line 1085: Required attribute 'select' is missing.

[xslt] : Fatal Error! Could not compile stylesheet

[xslt] Failed to process C:\SeleniumTestNg\TestNG\testng-results.xml

BUILD FAILED
C:\SeleniumTestNg\TestNG\build.xml:7: Fatal error during transformation


The above errors will occur if classpaths in build.xml are incorrect. It is better to leave testng-xslt\build.xml untouched after download. Below is an untouched snapshot of testng-xslt\build.xml.

<project name="testng-xslt" basedir=".">

   <property name="src.dir" value="src"/>
   <property name="lib.dir" value="lib"/>
   <property name="test.dir" value="test"/>
   <property name="version" value="1.1.1"/>

   <path id="test.classpath">
       <fileset dir="${lib.dir}" includes="*.jar"/>
   </path>

   <target name="test">
       <antcall target="testcase">
           <param name="dir" value="single"/>
       </antcall>

       <antcall target="test.css"/>

       <antcall target="testcase">
           <param name="dir" value="split-suite"/>
       </antcall>

       <antcall target="testcase">
           <param name="dir" value="split-suite-testcase"/>
       </antcall>

       <antcall target="test.runtimeTotals"/>
   </target>

   <libfileset dir="${lib.dir}" includes="*.jar"/>

   <target name="testcase">
       <property name="dir" value=""/>

       <mkdir dir="${test.dir}/${dir}/output"/>

       <xslt in="${test.dir}/${dir}/testng-results.xml" style="src/main/resources/testng-results.xsl"
             out="${test.dir}/${dir}/output/index.html" classpathref="test.classpath" processor="SaxonLiaison">
           <param name="testNgXslt.outputDir" expression="${basedir}/${test.dir}/${dir}/output/"/>
           <param name="testNgXslt.sortTestCaseLinks" expression="true"/>
           <param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS"/>
       </xslt>
   </target>

   <target name="test.css">
       <mkdir dir="${test.dir}/custom-css/output"/>

       <xslt in="${test.dir}/custom-css/testng-results.xml" style="src/main/resources/testng-results.xsl"
             out="${test.dir}/custom-css/output/index.html" classpathref="test.classpath" processor="SaxonLiaison">
           <param name="testNgXslt.outputDir" expression="${basedir}/${test.dir}/custom-css/output/"/>
           <param name="testNgXslt.cssFile" expression="../custom.css"/>
       </xslt>
   </target>

   <target name="test.runtimeTotals">
       <mkdir dir="${test.dir}/runtime-totals/output"/>

       <xslt in="${test.dir}/runtime-totals/testng-results.xml" style="src/main/resources/testng-results.xsl"
             out="${test.dir}/runtime-totals/output/index.html" classpathref="test.classpath" processor="SaxonLiaison">
           <param name="testNgXslt.outputDir" expression="${basedir}/${test.dir}/runtime-totals/output/"/>
           <param name="testNgXslt.showRuntimeTotals" expression="true"/>
       </xslt>
   </target>

   <target name="dist">
       <delete dir="." includes="*.zip"/>
       <zip destfile="testng-xslt-${version}.zip">
           <fileset dir="." includes="src/**"/>
           <fileset dir="." includes="lib/**"/>
           <fileset dir="." includes="test/**"/>
           <fileset dir="." includes="build.xml"/>
           <fileset dir="." includes="pom.xml"/>
       </zip>
   </target>

   <target name="clean">
       <delete dir="${test.dir}/single/output"/>
       <delete dir="${test.dir}/custom-css/output"/>
       <delete dir="${test.dir}/split-suite/output"/>
       <delete dir="${test.dir}/split-suite-testcase/output"/>
       <delete dir="${test.dir}/runtime-totals/output"/>
   </target>

</project>


Informational links

Selenium
Selenium Android Webdriver
TestNG
ReportNG
Testng-xslt
Apache ANT

Consider donating

Did this guide help you? Consider donating at http://spearhend.blogspot.com

The donate icon is on the top right and donations are accepted via Paypal.

Sunday, April 29, 2012

Google Nexus S: Building and Flashing Ice Cream Sandwich 4.0.4

Google Nexus S: Building and Flashing Ice Cream Sandwich 4.0.4


Disclaimer

Use this guide at your own risk. No guarantees/warranties are made regarding the accuracy of this guide or the fitness of this material for any particular task. Neither this guide nor its authors are liable for any damages, direct or indirect, incurred by following the instructions in this guide. There is always the risk of a device being bricked during the upgrade process.

Prerequisites

Linux box running Ubuntu 12.04 (Precise Pangolin) Desktop 64bit. This guide is based on a fresh clean install.

Things to Note

  1. 1.This guide makes minimal changes to your system. 
  2. 2.For the instructions to work, all the commands must be executed on a single terminal session. Read “Restarting interrupted build” in case the build needs to be continued post interruption. 
  3. 3.Pay attention to the PATH variable. It is set in various places. It is not added to any “profile” file. 
  4. 4.Linux working experience necessary. 



Setup working directory

Box:~/$ mkdir Work
Box:~/$ mkdir Work/bin
Box:~/$ mkdir Work/src
Box:~/$ cd Work

Download Java 6


Box:~/Work$ mv ~/Downloads/jdk-6u31-linux-x64.bin ./

Install Java locally

Box:~/Work$ sh ./jdk-6u31-linux-x64.bin
Box:~/Work$ export PATH=`pwd`/jdk1.6.0_31/bin:$PATH

Update packages

Box:~/Work$ sudo apt-get install git-core gnupg flex bison gperf build-essential   zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev   libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386   g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown   libxml2-utils xsltproc zlib1g-dev:i386

Install “repo”

“repo” is a convenience tool that makes it easier to download and work with Android sources.

Box:~/Work$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ./bin/repo
Box:~/Work$ chmod u+x ./bin/repo
Box:~/Work$ export PATH=`pwd`/bin:$PATH

Pull sources.

This step is time intensive. After this step, stay in src directory.

Box:~/Work$ cd src
Box:~/Work/src$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.4_r1
Box:~/Work/src$ repo sync
Pull and setup Nexus S binary drivers

Visit https://developers.google.com/android/nexus/drivers and download the right drivers for your device. Below is an example. On running the “sh” files, follow on-screen instructions to accept license.

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/akm-crespo-imm76d-8314bd5a.tgz > ./aakm-crespo-imm76d-8314bd5a.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/broadcom-crespo-iml74k-4b0a7e2a.tgz > ./broadcom-crespo-iml74k-4b0a7e2a.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/imgtec-crespo-iml74k-33420a2f.tgz > ./imgtec-crespo-iml74k-33420a2f.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/nxp-crespo-iml74k-9f2a89d1.tgz > ./nxp-crespo-iml74k-9f2a89d1.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/samsung-crespo-iml74k-0dbf413c.tgz > ./samsung-crespo-iml74k-0dbf413c.tgz

Box:~/Work/src$ for i in *.tgz; do tar -xvzf "./$i"; done
Box:~/Work/src$ for i in *.sh; do sh "./$i"; done

Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ make clobber


Build cache

According to google, this should speed up your rebuilds.

Box:~/Work/src$ export USE_CCACHE=1
Box:~/Work/src$ export CCACHE_DIR=`pwd`/../.ccache
Box:~/Work/src$ ./prebuilt/linux-x86/ccache/ccache -M 20G

Build

In the lunch menu, type “7” (full_crespo-userdebug). Time intensive step. Consider fixing build errors prior to this step.

Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ lunch
Box:~/Work/src$ make -j4



Build errors

The Build step should throw these errors. The “Fix” shows the changes made to resolve the error. These fixes have been discussed in various forums and blogs on the web.

Error

host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
<built-in>:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1

Fix

Box:~/Work/src$ repo diff build/core/combo/HOST_linux-x86.mk

project build/
diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk
index 5ae4972..7df2893 100644
--- a/core/combo/HOST_linux-x86.mk
+++ b/core/combo/HOST_linux-x86.mk
@@ -53,6 +53,6 @@ HOST_GLOBAL_CFLAGS += \
        -include $(call select-android-config-h,linux-x86)

 # Disable new longjmp in glibc 2.11 and later. See bug 2967937.
-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

 HOST_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined

Error

external/mesa3d/src/glsl/linker.cpp: In function ‘void assign_varying_locations(gl_shader_program*, gl_shader*, gl_shader*)’:
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1394:50: error: ‘varyings’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1394:58: error: ‘offsetof’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1395:48: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:48: error: ‘position’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1414:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1414:48: error: ‘pointSize’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1424:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1424:48: error: ‘position’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1428:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1428:48: error: ‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1431:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1431:48: error: ‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp: In function ‘void link_shaders(const gl_context*, gl_shader_program*)’:
external/mesa3d/src/glsl/linker.cpp:1734:49: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1734:50: error: ‘fragColor’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not declared in this scope
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1

Fix

Box:~/Work/src$ repo diff external/mesa3d/src/glsl/linker.cpp

project external/mesa3d/
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index f8b6962..f31e5b5 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -67,6 +67,7 @@
 #include <cstdio>
 #include <cstdarg>
 #include <climits>
+#include <stddef.h>

 #include <pixelflinger2/pixelflinger2_interface.h>

Error

host C++: liboprofile_pp <= external/oprofile/libpp/arrange_profiles.cpp
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
host C++: liboprofile_pp <= external/oprofile/libpp/callgraph_container.cpp
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1

Fix

Box:~/Work/src$ repo diff external/oprofile/libpp/format_output.h

project external/oprofile/
diff --git a/libpp/format_output.h b/libpp/format_output.h
index b6c4592..8e527d5 100644
--- a/libpp/format_output.h
+++ b/libpp/format_output.h
@@ -91,7 +91,7 @@ protected:
                symbol_entry const & symbol;
                sample_entry const & sample;
                size_t pclass;
-               mutable counts_t & counts;
+               counts_t & counts;
                extra_images const & extra;
                double diff;
        };

Error

external/hyphenation/hyphen.c:404:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/gtest_main.cc:32:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/../src/gtest.cc:34,
                 from external/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_main_host_intermediates/gtest_main.o] Error 1

Fix

Box:~/Work/src$ repo diff  external/gtest/include/gtest/internal/gtest-param-util.h

project external/gtest/
diff --git a/include/gtest/internal/gtest-param-util.h b/include/gtest/internal/gtest-param-util.h
index 5559ab4..405dc4d 100644
--- a/include/gtest/internal/gtest-param-util.h
+++ b/include/gtest/internal/gtest-param-util.h
@@ -37,6 +37,7 @@
 #include <iterator>
 #include <utility>
 #include <vector>
+#include <cstddef>

 #include <gtest/internal/gtest-port.h>
Error

out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1

Fix

Box:~/Work/src$ repo diff external/llvm/llvm-host-build.mk

project external/llvm/
diff --git a/llvm-host-build.mk b/llvm-host-build.mk
index 5219efd..53a6229 100644
--- a/llvm-host-build.mk
+++ b/llvm-host-build.mk
@@ -10,6 +10,8 @@ LOCAL_CFLAGS :=       \
        -Wwrite-strings \
        $(LOCAL_CFLAGS)

+LOCAL_LDLIBS := -lpthread -ldl
+
 ifeq ($(LLVM_ENABLE_ASSERTION),true)
 LOCAL_CFLAGS :=        \
        -D_DEBUG        \

Error

host C++: llvm-rs-cc <= frameworks/compile/slang/slang_rs_export_foreach.cpp
host C++: llvm-rs-cc <= frameworks/compile/slang/slang_rs_object_ref_count.cpp
frameworks/compile/slang/slang_rs_export_foreach.cpp: In static member function ‘static slang::RSExportForEach* slang::RSExportForEach::Create(slang::RSContext*, const clang::FunctionDecl*)’:
frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs_export_foreach.o] Error 1

Fix

Box:~/Work/src$ repo diff frameworks/compile/slang/slang_rs_export_foreach.cpp

project frameworks/compile/slang/
diff --git a/slang_rs_export_foreach.cpp b/slang_rs_export_foreach.cpp
index a4025ca..0dbf954 100644
--- a/slang_rs_export_foreach.cpp
+++ b/slang_rs_export_foreach.cpp
@@ -246,7 +246,6 @@ RSExportForEach *RSExportForEach::Create(RSContext *Context,
                                     clang::SourceLocation(),
                                     &Ctx.Idents.get(Id));
 
-      llvm::StringRef ParamName = PVD->getName();
       clang::FieldDecl *FD =
           clang::FieldDecl::Create(Ctx,
                                    RD,

Add build output tools to PATH

Box:~/Work/src$ export PATH=`pwd`/out/host/linux-x86/bin:$PATH

Nexus S udev rules

This is needed for your device to be detected by ADB. Execute the below commands and then connect your Nexus S.

Box:~/Work/src$ sudo bash
Box:~/Work/src# echo SUBSYSTEM==\"usb\", ATTR{idVendor}==\"04e8\", MODE=\"0666\", GROUP=\"plugdev\" >> /etc/udev/rules.d/51-android.rules
Box:~/Work/src# chmod a+r /etc/udev/rules.d/51-android.rules
Box:~/Work/src# service udev restart






Flash the device

Perform flashing as root, to avoid permission issues.

Box:~/Work/src$ sudo bash
Box:~/Work/src# export PATH=`pwd`/out/host/linux-x86/bin:$PATH
Box:~/Work/src# adb reboot bootloader
Box:~/Work/src# fastboot oem unlock
Box:~/Work/src# fastboot erase cache
Box:~/Work/src# fastboot erase userdata
Box:~/Work/src# export ANDROID_PRODUCT_OUT=`pwd`/out/target/product/crespo
Box:~/Work/src# fastboot flashall

Restarting interrupted build

This section should serve as an example. Depending on where the build was interrupted, additional commands may have to be executed to continue.

Set the paths and continue as before.

Box:~/$ cd Work
Box:~/Work$ export PATH=`pwd`/jdk1.6.0_31/bin:$PATH
Box:~/Work$ export PATH=`pwd`/bin:$PATH
Box:~/Work$ cd src
Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ make -j4

Reverting back to stock firmware

Download the stock version for your device from https://developers.google.com/android/nexus/images

Below is an example that uses soju-imm76d-factory-ca4ae9ee.tgz (4.0.4). We assume that the existing build is valid. “fastboot” is needed from the earlier build. Root is needed to avoid any permission problems.

Box:~/$ cd Work
Box:~/Work$ mkdir stock
Box:~/Work$ mv ~/Downloads/soju-imm76d-factory-ca4ae9ee.tgz stock
Box:~/Work$ cd stock/
Box:~/Work/stock$ tar -xvzf soju-imm76d-factory-ca4ae9ee.tgz
Box:~/Work/stock$ cd soju-imm76d/
Box:~/Work/stock/soju-imm76d$ sudo bash
Box:~/Work/stock/soju-imm76d# export PATH=~/Work/src/out/host/linux-x86/bin:$PATH
Box:~/Work/stock/soju-imm76d# adb reboot bootloader
Box:~/Work/stock/soju-imm76d# sh flash-all.sh

Version numbers

Box:~/Work/src$ make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

Box:~/Work/src$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Box:~/Work/src$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

Box:~/Work/src$ python --version
Python 2.7.3

Informational links



Consider Donating

Did this guide help you? Consider donating at http://spearhend.blogspot.com

The donate icon is on the top right and donations are accepted via Paypal.

PDF Version