Enable PPAPI browser tests for Non-SFI ARM.

- Add rules for building browser tests for Non-SFI ARM
- Enable browser tests for Non-SFI ARM
- Modify create_nonsfi_test_nmf.py to support Non-SFI ARM

BUG=372049
TEST=try bot with linux_arm and linux_arm_tester

Review URL: https://codereview.chromium.org/687543002

Cr-Commit-Position: refs/heads/master@{#304000}
diff --git a/chrome/browser_tests.isolate b/chrome/browser_tests.isolate
index fb2d083..be11cf8 100644
--- a/chrome/browser_tests.isolate
+++ b/chrome/browser_tests.isolate
@@ -106,7 +106,8 @@
         ],
       },
     }],
-    ['disable_nacl==0 and OS=="linux" and target_arch=="ia32"', {
+    [('disable_nacl==0 and OS=="linux" and '
+      '(target_arch=="ia32" or target_arch=="arm")'), {
       'variables': {
         'files': [
           '<(PRODUCT_DIR)/ppapi_nacl_tests_pnacl_nonsfi.nmf',
@@ -118,6 +119,7 @@
         'files': [
           '<(PRODUCT_DIR)/ppapi_nacl_tests_newlib_arm.nexe',
           '<(PRODUCT_DIR)/ppapi_nacl_tests_pnacl_newlib_arm.nexe',
+          '<(PRODUCT_DIR)/ppapi_nacl_tests_pnacl_newlib_arm_nonsfi.nexe',
         ],
       },
     }],
diff --git a/chrome/test/data/nacl/nacl_test_data.gyp b/chrome/test/data/nacl/nacl_test_data.gyp
index 9c94a1b2..d45dc9a 100644
--- a/chrome/test/data/nacl/nacl_test_data.gyp
+++ b/chrome/test/data/nacl/nacl_test_data.gyp
@@ -37,13 +37,21 @@
       },
       'conditions': [
         ['target_arch=="ia32" and OS=="linux"', {
-          # Enable nonsfi testing only on ia32-linux environment.
+          # Enable nonsfi testing on ia32-linux environment.
           # This flag causes test_files to be copied into nonsfi directory,
           # too.
           'variables': {
             'enable_x86_32_nonsfi': 1,
           },
         }],
+        ['target_arch=="arm" and OS=="linux"', {
+          # Enable nonsfi testing on arm-linux environment.
+          # This flag causes test_files to be copied into nonsfi directory,
+          # too.
+          'variables': {
+            'enable_arm_nonsfi': 1,
+          },
+        }],
       ],
     },
     {
@@ -549,21 +557,29 @@
         'nacl_ppapi_util',
       ],
       'conditions': [
+        # These are needed to build a non-SFI nexe binary.
+        # Note that these trigger building nexe files for other
+        # architectures, such as x86-32 (based on enable_XXX variables).
+        # As described above, although the tests for pnacl are currently
+        # disabled, but building the binary should work.
+        # We cannot disable building, as enable_XXX variables are also used
+        # to build newlib linked nexes.
         ['target_arch=="ia32" and OS=="linux"', {
-          # Enable nonsfi testing only on ia32-linux environment.
+          # Enable nonsfi testing on ia32-linux environment.
           'variables': {
-            # This is needed to build a non-SFI nexe binary.
-            # Note that this triggers building nexe files for other
-            # architectures, such as x86-32 (based on enable_XXX variables).
-            # As described above, although the tests for pnacl are currently
-            # disabled, but building the binary should work.
-            # We cannot disable building, as enable_XXX variables are also used
-            # to build newlib linked nexes.
             'build_pnacl_newlib': 1,
             'translate_pexe_with_build': 1,
             'enable_x86_32_nonsfi': 1,
           },
         }],
+        ['target_arch=="arm" and OS=="linux"', {
+          # Enable nonsfi testing on arm-linux environment.
+          'variables': {
+            'build_pnacl_newlib': 1,
+            'translate_pexe_with_build': 1,
+            'enable_arm_nonsfi': 1,
+          },
+        }],
       ],
     },
     {
@@ -603,12 +619,19 @@
       ],
       'conditions': [
         ['target_arch=="ia32" and OS=="linux"', {
-          # Enable nonsfi testing only on ia32-linux environment.
+          # Enable nonsfi testing on ia32-linux environment.
           'variables': {
             'enable_x86_32_nonsfi': 1,
             'translate_pexe_with_build': 1,
           },
         }],
+        ['target_arch=="arm" and OS=="linux"', {
+          # Enable nonsfi testing on arm-linux environment.
+          'variables': {
+            'enable_arm_nonsfi': 1,
+            'translate_pexe_with_build': 1,
+          },
+        }],
       ],
     },
     {
diff --git a/chrome/test/nacl/nacl_browsertest_util.h b/chrome/test/nacl/nacl_browsertest_util.h
index 4a7c3c6..ac084d0a 100644
--- a/chrome/test/nacl/nacl_browsertest_util.h
+++ b/chrome/test/nacl/nacl_browsertest_util.h
@@ -182,8 +182,8 @@
 #endif
 
 // Currently, translation from pexe to non-sfi nexe is supported only for
-// x86-32 binary.
-#if defined(OS_LINUX) && defined(ARCH_CPU_X86)
+// x86-32 or ARM binary.
+#if defined(OS_LINUX) && (defined(ARCH_CPU_X86) || defined(ARCH_CPU_ARMEL))
 #  define MAYBE_PNACL_NONSFI(test_case) test_case
 #else
 #  define MAYBE_PNACL_NONSFI(test_case) DISABLED_##test_case
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_irt_shim.gyp b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_irt_shim.gyp
index f7812649..a2e9e1f 100644
--- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_irt_shim.gyp
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_irt_shim.gyp
@@ -25,6 +25,8 @@
         # variable, as it is no longer used.
         'out_pnacl_newlib_x86_32_nonsfi': '>(tc_lib_dir_pnacl_translate)/lib-x86-32-nonsfi/>(nlib_target)',
         'out_newlib32_nonsfi': '>(tc_lib_dir_pnacl_translate)/lib-x86-32-nonsfi/>(nlib_target)',
+        'out_pnacl_newlib_arm_nonsfi': '>(tc_lib_dir_pnacl_translate)/lib-arm-nonsfi/>(nlib_target)',
+        'out_newlib_arm_nonsfi': '>(tc_lib_dir_pnacl_translate)/lib-arm-nonsfi/>(nlib_target)',
         'build_glibc': 0,
         'build_newlib': 0,
         'build_pnacl_newlib': 1,
@@ -34,6 +36,7 @@
         'enable_arm': 1,
         'enable_mips': 1,
         'enable_x86_32_nonsfi': 1,
+        'enable_arm_nonsfi': 1,
         'sources': [
           'irt_shim_ppapi.c',
           'pnacl_shim.c',
diff --git a/ppapi/ppapi_nacl.gyp b/ppapi/ppapi_nacl.gyp
index 1d75eed8..bbad955 100644
--- a/ppapi/ppapi_nacl.gyp
+++ b/ppapi/ppapi_nacl.gyp
@@ -235,14 +235,26 @@
             },
           ],
         }],
-        ['disable_pnacl==0 and target_arch=="ia32" and OS=="linux"', {
-          # In addition to above configuration, build x86-32-nonsfi .nexe file
-          # by translating from .pexe binary, for non-SFI mode PPAPI testing.
+        ['disable_pnacl==0 and (target_arch=="ia32" or target_arch=="arm") and OS=="linux"', {
+          # In addition to above configuration, build x86-32 and arm nonsfi
+          # .nexe files by translating from .pexe binary, for non-SFI mode PPAPI
+          # testing.
           'variables': {
-            'enable_x86_32_nonsfi': 1,
             'translate_pexe_with_build': 1,
             'nmf_nonsfi%': '<(PRODUCT_DIR)/>(nexe_target)_pnacl_nonsfi.nmf',
           },
+          'conditions': [
+            ['target_arch=="ia32"', {
+              'variables': {
+                'enable_x86_32_nonsfi': 1,
+              },
+            }],
+            ['target_arch=="arm"', {
+              'variables': {
+                'enable_arm_nonsfi': 1,
+              },
+            }],
+          ],
           # Shim is a dependency for the nexe because we pre-translate.
          'dependencies': [
             '<(DEPTH)/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_irt_shim.gyp:aot',
@@ -256,7 +268,20 @@
                 'python',
                 '>(create_nonsfi_test_nmf)',
                 '--output=>(nmf_nonsfi)',
-                '--program=>(out_pnacl_newlib_x86_32_nonsfi_nexe)',
+              ],
+              'target_conditions': [
+                ['enable_x86_32_nonsfi==1', {
+                  'action': [
+                    '--program=>(out_pnacl_newlib_x86_32_nonsfi_nexe)',
+                    '--arch=x86-32',
+                  ],
+                }],
+                ['enable_arm_nonsfi==1', {
+                  'action': [
+                    '--program=>(out_pnacl_newlib_arm_nonsfi_nexe)',
+                    '--arch=arm',
+                  ],
+                }],
               ],
             },
           ],
diff --git a/ppapi/ppapi_nacl_test_common.gypi b/ppapi/ppapi_nacl_test_common.gypi
index 3ebd8a0f..ca119fe 100644
--- a/ppapi/ppapi_nacl_test_common.gypi
+++ b/ppapi/ppapi_nacl_test_common.gypi
@@ -35,6 +35,7 @@
           'out_pnacl_newlib%': '>(nacl_pnacl_newlib_out_dir)/>(nexe_target)_newlib_pnacl.pexe',
           'nmf_pnacl_newlib%': '>(nacl_pnacl_newlib_out_dir)/>(nexe_target).nmf',
           'out_pnacl_newlib_x86_32_nonsfi_nexe': '>(nacl_pnacl_newlib_nonsfi_out_dir)/>(nexe_target)_pnacl_newlib_x32_nonsfi.nexe',
+          'out_pnacl_newlib_arm_nonsfi_nexe': '>(nacl_pnacl_newlib_nonsfi_out_dir)/>(nexe_target)_pnacl_newlib_arm_nonsfi.nexe',
           'nmf_pnacl_newlib_nonsfi%': '>(nacl_pnacl_newlib_nonsfi_out_dir)/>(nexe_target).nmf',
         }],
       ],
@@ -77,7 +78,7 @@
           },
         ],
       }],
-      ['test_files!=[] and build_pnacl_newlib==1 and enable_x86_32_nonsfi==1', {
+      ['test_files!=[] and build_pnacl_newlib==1 and (enable_x86_32_nonsfi==1 or enable_arm_nonsfi==1)', {
         'copies': [
           {
             'destination': '>(nacl_pnacl_newlib_nonsfi_out_dir)',
@@ -209,22 +210,33 @@
               },
             ],
           }],
-          ['generate_nmf==1 and build_pnacl_newlib==1 and disable_pnacl==0 and enable_x86_32_nonsfi==1', {
+          ['generate_nmf==1 and build_pnacl_newlib==1 and disable_pnacl==0 and (enable_x86_32_nonsfi==1 or enable_arm_nonsfi==1)', {
             'actions': [
               {
                 'action_name': 'Generate PNACL NEWLIB nonsfi NMF',
-                # If we add support for ARM, we should split the dependency on
-                # out_pnacl_newlib_x86_32_nonsfi_nexe to 'target_conditions',
-                # similar to build_newlib=1 config declared above.
-                'inputs': ['>(create_nonsfi_test_nmf)',
-                           '>(out_pnacl_newlib_x86_32_nonsfi_nexe)'],
+                'inputs': ['>(create_nonsfi_test_nmf)'],
                 'outputs': ['>(nmf_pnacl_newlib_nonsfi)'],
                 'action': [
                   'python',
                   '>(create_nonsfi_test_nmf)',
+                  '>@(create_nmf_args_portable)',
                   '--output=>(nmf_pnacl_newlib_nonsfi)',
-                  '--program=>(out_pnacl_newlib_x86_32_nonsfi_nexe)',
-                  '>@(create_nmf_args_portable)'
+                ],
+                'target_conditions': [
+                  ['enable_x86_32_nonsfi==1', {
+                    'inputs': ['>(out_pnacl_newlib_x86_32_nonsfi_nexe)'],
+                    'action': [
+                      '--program=>(out_pnacl_newlib_x86_32_nonsfi_nexe)',
+                      '--arch=x86-32',
+                    ]
+                  }],
+                  ['enable_arm_nonsfi==1', {
+                    'inputs': ['>(out_pnacl_newlib_arm_nonsfi_nexe)'],
+                    'action': [
+                      '--program=>(out_pnacl_newlib_arm_nonsfi_nexe)',
+                      '--arch=arm',
+                    ]
+                  }],
                 ],
               },
             ],
diff --git a/ppapi/tests/create_nonsfi_test_nmf.py b/ppapi/tests/create_nonsfi_test_nmf.py
index 337d069..3ac4e502 100755
--- a/ppapi/tests/create_nonsfi_test_nmf.py
+++ b/ppapi/tests/create_nonsfi_test_nmf.py
@@ -19,18 +19,20 @@
 import json
 import logging
 import os
+import sys
 
 _FILES_KEY = 'files'
 _PORTABLE_KEY = 'portable'
 _PROGRAM_KEY = 'program'
 _URL_KEY = 'url'
-_X86_32_NONSFI_KEY = 'x86-32-nonsfi'
-
 
 def ParseArgs():
   parser = argparse.ArgumentParser()
   parser.add_argument(
       '--program', metavar='FILE', help='Main program nexe')
+  parser.add_argument(
+      '--arch', metavar='ARCH', choices=('x86-32', 'arm'),
+      help='The archtecture of main program nexe')
   # To keep compatibility with create_nmf.py, we use -x and --extra-files
   # as flags.
   parser.add_argument(
@@ -43,14 +45,15 @@
   return parser.parse_args()
 
 
-def BuildNmfMap(root_path, program, extra_files):
+def BuildNmfMap(root_path, program, arch, extra_files):
   """Build simple map representing nmf json."""
+  nonsfi_key = arch + '-nonsfi'
   result = {
     _PROGRAM_KEY: {
-      _X86_32_NONSFI_KEY: {
+      nonsfi_key: {
         # The program path is relative to the root_path.
         _URL_KEY: os.path.relpath(program, root_path)
-      }
+      },
     }
   }
 
@@ -81,12 +84,15 @@
   if not args.program:
     logging.error('--program is not specified.')
     sys.exit(1)
+  if not args.arch:
+    logging.error('--arch is not specified.')
+    sys.exit(1)
   if not args.output:
     logging.error('--output is not specified.')
     sys.exit(1)
 
   nmf_map = BuildNmfMap(os.path.dirname(args.output),
-                        args.program, args.extra_files)
+                        args.program, args.arch, args.extra_files)
   OutputNmf(nmf_map, args.output)