diff options
244 files changed, 5851 insertions, 4932 deletions
@@ -112,3 +112,4 @@ a license to everyone to use it as detailed in LICENSE.) * Lu Wang <coolwanglu@gmail.com> * Heidi Pan <heidi.pan@intel.com> (copyright owned by Intel) * Vasilis Kalintiris <ehostunreach@gmail.com> +* Adam C. Clifton <adam@hulkamaniac.com> @@ -499,6 +499,11 @@ Options that are modified or new in %s include: --proxy-to-worker Generates both html and js files. The main program is in js, and the html proxies to/from it. + --emrun Enables the generated output to be aware of the + emrun command line tool. This allows stdout, stderr + and exit(returncode) capture when running the + generated application through emrun. + --em-config Specifies the location of the .emscripten configuration file for the current compiler run. If not specified, the environment variable EM_CONFIG is read for this @@ -780,6 +785,7 @@ try: shell_path = shared.path_from_root('src', 'shell.html') js_libraries = [] bind = False + emrun = False jcache = False save_bc = False memory_init_file = False @@ -969,16 +975,23 @@ try: if not absolute_warning_shown and os.path.isabs(path_name): logging.warning ('-I or -L of an absolute path "' + newargs[i] + '" encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript). Pass \'-Wno-warn-absolute-paths\' to emcc to hide this warning.') # Of course an absolute path to a non-system-specific library or header is fine, and you can ignore this warning. The danger are system headers that are e.g. x86 specific and nonportable. The emscripten bundled headers are modified to be portable, local system ones are generally not absolute_warning_shown = True + elif newargs[i] == '--emrun': + emrun = True + newargs[i] = '' elif newargs[i] == '--em-config': # This option is parsed in tools/shared.py, here only clean it up from being passed to clang. newargs[i] = '' newargs[i+1] = '' + newargs = [ arg for arg in newargs if arg is not '' ] # If user did not specify a default -std for C++ code, specify the emscripten default. if default_cxx_std: newargs = newargs + [default_cxx_std] + if emrun: + post_js += open(shared.path_from_root('src', 'emrun_postjs.js')).read() + '\n' + if js_opts is None: js_opts = opt_level >= 2 if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level] if llvm_lto is None and opt_level >= 3: llvm_lto = 3 @@ -1153,11 +1166,10 @@ try: heap = 4096 while heap < shared.Settings.TOTAL_MEMORY: - heap *= 2 - #if heap <= 16*1024*1024: - # heap *= 2 - #else: - # heap += 16*1024*1024 + if heap < 16*1024*1024: + heap *= 2 + else: + heap += 16*1024*1024 if heap != shared.Settings.TOTAL_MEMORY: logging.warning('increasing TOTAL_MEMORY to %d to be more reasonable for asm.js' % heap) shared.Settings.TOTAL_MEMORY = heap @@ -0,0 +1,918 @@ +#!/usr/bin/env python + +# emrun: Implements machinery that allows running a .html page as if it was a standard executable file. +# Usage: emrun <options> filename.html <args to program> +# See emrun --help for more information + +import os, platform, optparse, logging, re, pprint, atexit, urlparse, subprocess, sys, SocketServer, BaseHTTPServer, SimpleHTTPServer, time, string, struct, socket, cgi +from operator import itemgetter +from urllib import unquote +from Queue import PriorityQueue + +# Populated from cmdline params +emrun_options = None + +# Represents the process object handle to the browser we opened to run the html page. +browser_process = None + +# If we have routed browser output to file with --log_stdout and/or --log_stderr, +# these track the handles. +browser_stdout_handle = sys.stdout +browser_stderr_handle = sys.stderr + +# This flag tracks whether the html page has sent any stdout messages back to us. +# Used to detect whether we might have gotten detached from the browser process we +# spawned, in which case we are not able to detect when user closes the browser with +# the close button. +have_received_messages = False + +# At startup print a warning message once if user did not build with --emrun. +emrun_not_enabled_nag_printed = False + +# Stores the exit() code of the html page when/if it quits. +page_exit_code = 0 + +# If this is set to a non-empty string, all processes by this name will be killed at exit. +# This is used to clean up after browsers that spawn subprocesses to handle the actual +# browser launch. For example opera has a launcher.exe that runs the actual opera browser. +# So killing browser_process would just kill launcher.exe and not the opera browser itself. +processname_killed_atexit = "" + +# If user does not specify a --port parameter, this port is used to launch the server. +default_webserver_port = 6931 + +# Host OS detection to autolocate browsers and other OS-specific support needs. +WINDOWS = False +LINUX = False +OSX = False +if os.name == 'nt': + WINDOWS = True + + import win32api, _winreg + from win32com.client import GetObject + from win32api import GetFileVersionInfo, LOWORD, HIWORD + import shlex + from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValue + +elif platform.system() == 'Linux': + LINUX = True +elif platform.mac_ver()[0] != '': + OSX = True + + import plistlib + +# If you are running on an OS that is not any of these, must add explicit support for it. +if not WINDOWS and not LINUX and not OSX: + raise Exception("Unknown OS!") + +# Absolute wallclock time in seconds specifying when the previous HTTP stdout message from +# the page was received. +last_message_time = time.clock() + +# Absolute wallclock time in seconds telling when we launched emrun. +page_start_time = time.clock() + +# Stores the time of most recent http page serve. +page_last_served_time = time.clock() + +# Returns given log message formatted to be outputted on a HTML page. +def format_html(msg): + if not msg.endswith('\n'): + msg += '\n' + msg = cgi.escape(msg) + msg = msg.replace('\r\n', '<br />').replace('\n', '<br />') + return msg + +# Prints a log message to 'info' stdout channel. Always printed. +def logi(msg): + global last_message_time + if emrun_options.log_html: + sys.stdout.write(format_html(msg)) + else: + print >> sys.stdout, msg + sys.stdout.flush() + last_message_time = time.clock() + +# Prints a verbose log message to stdout channel. Only shown if run with --verbose. +def logv(msg): + global emrun_options, last_message_time + if emrun_options.verbose: + if emrun_options.log_html: + sys.stdout.write(format_html(msg)) + else: + print >> sys.stdout, msg + sys.stdout.flush() + last_message_time = time.clock() + +# Prints an error message to stderr channel. +def loge(msg): + global last_message_time + if emrun_options.log_html: + sys.stderr.write(format_html(msg)) + else: + print >> sys.stderr, msg + sys.stderr.flush() + last_message_time = time.clock() + +def format_eol(msg): + if WINDOWS: + msg = msg.replace('\r\n', '\n').replace('\n', '\r\n') + return msg + +# Prints a message to the browser stdout output stream. +def browser_logi(msg): + global browser_stdout_handle + if browser_stdout_handle != sys.stdout and not msg.endswith('\n'): + msg += '\n' + msg = format_eol(msg) + print >> browser_stdout_handle, msg + browser_stdout_handle.flush() + last_message_time = time.clock() + +# Prints a message to the browser stderr output stream. +def browser_loge(msg): + global browser_stderr_handle + if browser_stderr_handle != sys.stderr and not msg.endswith('\n'): + msg += '\n' + msg = format_eol(msg) + print >> browser_stderr_handle, msg + browser_stderr_handle.flush() + last_message_time = time.clock() + +# Unquotes a unicode string. (translates ascii-encoded utf string back to utf) +def unquote_u(source): + result = unquote(source) + if '%u' in result: + result = result.replace('%u','\\u').decode('unicode_escape') + return result + +# Returns whether the browser page we spawned is still running. +# (note, not perfect atm, in case we are running in detached mode) +def is_browser_process_alive(): + return browser_process and browser_process.poll() == None + +# Kills browser_process and processname_killed_atexit. +def kill_browser_process(): + global browser_process, processname_killed_atexit + if browser_process: + try: + logv('Terminating browser process..') + browser_process.kill() + except: + pass + browser_process = None + + if len(processname_killed_atexit) > 0: + logv("Terminating all processes that have string '" + processname_killed_atexit + "' in their name.") + if WINDOWS: + process_image = processname_killed_atexit if '.exe' in processname_killed_atexit else (processname_killed_atexit + '.exe') + process = subprocess.Popen(['taskkill', '/F', '/IM', process_image, '/T'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process.communicate() + else: + try: + subprocess.call(['pkill', processname_killed_atexit]) + except OSError, e: + try: + subprocess.call(['killall', processname_killed_atexit]) + except OSError, e: + loge('Both commands pkill and killall failed to clean up the spawned browser process. Perhaps neither of these utilities is available on your system?') + processname_killed_atexit = '' + +# Our custom HTTP web server that will server the target page to run via .html. +# This is used so that we can load the page via a http:// URL instead of a file:// URL, since those wouldn't work too well unless user allowed XHR without CORS rules. +# Also, the target page will route its stdout and stderr back to here via HTTP requests. +class HTTPWebServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): + # Log messaging arriving via HTTP can come in out of sequence. Implement a sequencing mechanism to enforce ordered transmission. + expected_http_seq_num = -1 + # Stores messages that have arrived out of order, pending for a send as soon as the missing message arrives. + # Kept in sorted order, first element is the oldest message received. + http_message_queue = [] + + def handle_incoming_message(self, seq_num, log, data): + global have_received_messages + have_received_messages = True + + if self.expected_http_seq_num == -1: + self.expected_http_seq_num = seq_num+1 + log(data) + elif seq_num == -1: # Message arrived without a sequence number? Just log immediately + log(data) + elif seq_num == self.expected_http_seq_num: + log(data) + self.expected_http_seq_num += 1 + self.print_messages_due() + elif seq_num < self.expected_http_seq_num: + log(data) + else: + log(data) + self.http_message_queue += [(seq_num, data, log)] + self.http_message_queue.sort(key=itemgetter(0)) + if len(self.http_message_queue) > 16: + self.print_next_message() + + # If it's been too long since we we got a message, prints out the oldest queued message, ignoring the proper order. + # This ensures that if any messages are actually lost, that the message queue will be orderly flushed. + def print_timed_out_messages(self): + global last_message_time + now = time.clock() + max_message_queue_time = 5 + if len(self.http_message_queue) > 0 and now - last_message_time > max_message_queue_time: + self.print_next_message() + + # Skips to printing the next message in queue now, independent of whether there was missed messages in the sequence numbering. + def print_next_message(self): + if len(self.http_message_queue) > 0: + self.expected_http_seq_num = self.http_message_queue[0][0] + self.print_messages_due() + + # Completely flushes all out-of-order messages in the queue. + def print_all_messages(self): + while len(self.http_message_queue) > 0: + self.print_next_message() + + # Prints any messages that are now due after we logged some other previous messages. + def print_messages_due(self): + while len(self.http_message_queue) > 0: + msg = self.http_message_queue[0] + if msg[0] == self.expected_http_seq_num: + msg[2](msg[1]) + self.expected_http_seq_num += 1 + self.http_message_queue.pop(0) + else: + return + + def serve_forever(self, timeout=0.5): + global emrun_options, last_message_time, page_exit_code, have_received_messages, emrun_not_enabled_nag_printed + self.is_running = True + self.timeout = timeout + while self.is_running: + now = time.clock() + # Did user close browser? + if not emrun_options.serve_after_close and browser_process and browser_process.poll() != None: + if not have_received_messages: + emrun_options.serve_after_close = True + logv('Warning: emrun got detached from the target browser process. Cannot detect when user closes the browser. Behaving as if --serve_after_close was passed in.') + else: + self.shutdown() + logv('Browser process has quit. Shutting down web server.. Pass --serve_after_close to keep serving the page even after the browser closes.') + + # Serve HTTP + self.handle_request() + # Process message log queue + self.print_timed_out_messages() + + # If web page was silent for too long without printing anything, kill process. + time_since_message = now - last_message_time + if emrun_options.silence_timeout != 0 and time_since_message > emrun_options.silence_timeout: + self.shutdown() + logv('No activity in ' + str(emrun_options.silence_timeout) + ' seconds. Quitting web server with return code ' + str(emrun_options.timeout_returncode) + '. (--silence_timeout option)') + page_exit_code = emrun_options.timeout_returncode + emrun_options.kill_on_exit = True + + # If the page has been running too long as a whole, kill process. + time_since_start = now - page_start_time + if emrun_options.timeout != 0 and time_since_start > emrun_options.timeout: + self.shutdown() + logv('Page has not finished in ' + str(emrun_options.timeout) + ' seconds. Quitting web server with return code ' + str(emrun_options.timeout_returncode) + '. (--timeout option)') + emrun_options.kill_on_exit = True + page_exit_code = emrun_options.timeout_returncode + + # If we detect that the page is not running with emrun enabled, print a warning message. + time_since_page_serve = now - page_last_served_time + if not emrun_not_enabled_nag_printed and not have_received_messages and time_since_page_serve > 5: + logi('The html page you are running is not emrun-capable. Stdout, stderr and exit(returncode) capture will not work. Recompile the application with the --emrun linker flag to enable this, or pass --no_emrun_detect to emrun to hide this check.') + emrun_not_enabled_nag_printed = True + + # Clean up at quit, print any leftover messages in queue. + self.print_all_messages() + + def handle_error(self, request, client_address): + err = sys.exc_info()[1][0] + # Filter out the useless '[Errno 10054] An existing connection was forcibly closed by the remote host' errors that occur when we + # forcibly kill the client. + if err != 10054: + SocketServer.BaseServer.handle_error(self, request, client_address) + + def shutdown(self): + self.is_running = False + self.print_all_messages() + return 1 + +# Processes HTTP request back to the browser. +class HTTPHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def send_head(self): + global page_last_served_time + path = self.translate_path(self.path) + f = None + + if os.path.isdir(path): + if not self.path.endswith('/'): + self.send_response(301) + self.send_header("Location", self.path + "/") + self.end_headers() + return None + for index in "index.html", "index.htm": + index = os.path.join(path, index) + if os.path.isfile(index): + path = index + break + else: + # Manually implement directory listing support. + return self.list_directory(path) + ctype = self.guess_type(path) + try: + f = open(path, 'rb') + except IOError: + self.send_error(404, "File not found: " + path) + return None + self.send_response(200) + self.send_header("Content-type", ctype) + fs = os.fstat(f.fileno()) + self.send_header("Content-Length", str(fs[6])) + self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) + self.send_header('Cache-Control','no-cache, must-revalidate') + self.send_header('Expires','-1') + self.end_headers() + page_last_served_time = time.clock() + return f + + def log_request(self, code): + # Filter out 200 OK messages to remove noise. + if code is not 200: + SimpleHTTPServer.SimpleHTTPRequestHandler.log_request(self, code) + + def log_message(self, format, *args): + msg = "%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args) + if not 'favicon.ico' in msg: # Filter out 404 messages on favicon.ico not being found to remove noise. + sys.stderr.write(msg) + + def do_POST(self): + global page_exit_code, emrun_options, have_received_messages + + (_, _, path, query, _) = urlparse.urlsplit(self.path) + data = self.rfile.read(int(self.headers['Content-Length'])) + data = data.replace("+", " ") + data = unquote_u(data) + + # The user page sent a message with POST. Parse the message and log it to stdout/stderr. + is_stdout = False + is_stderr = False + seq_num = -1 + # The html shell is expected to send messages of form ^out^(number)^(message) or ^err^(number)^(message). + if data.startswith('^err^'): + is_stderr = True + elif data.startswith('^out^'): + is_stdout = True + if is_stderr or is_stdout: + try: + i = data.index('^', 5) + seq_num = int(data[5:i]) + data = data[i+1:] + except: + pass + + is_exit = data.startswith('^exit^') + + if data == '^pageload^': # Browser is just notifying that it has successfully launched the page. + have_received_messages = True + elif not is_exit: + log = browser_loge if is_stderr else browser_logi + self.server.handle_incoming_message(seq_num, log, data) + elif not emrun_options.serve_after_exit: + page_exit_code = int(data[6:]) + logv('Web page has quit with a call to exit() with return code ' + str(page_exit_code) + '. Shutting down web server. Pass --serve_after_exit to keep serving even after the page terminates with exit().') + self.server.shutdown() + + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.send_header('Cache-Control','no-cache, must-revalidate') + self.send_header('Expires','-1') + self.end_headers() + self.wfile.write('OK') + +# From http://stackoverflow.com/questions/4842448/getting-processor-information-in-python +# Returns a string with something like "AMD64, Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz, Intel64 Family 6 Model 42 Stepping 7, GenuineIntel" +def get_cpu_infoline(): + try: + if WINDOWS: + root_winmgmts = GetObject("winmgmts:root\cimv2") + cpus = root_winmgmts.ExecQuery("Select * from Win32_Processor") + cpu_name = cpus[0].Name + ', ' + platform.processor() + elif OSX: + cpu_name = subprocess.check_output(['sysctl', '-n', 'machdep.cpu.brand_string']).strip() + elif LINUX: + command = "cat /proc/cpuinfo" + all_info = subprocess.check_output(command, shell=True).strip() + for line in all_info.split("\n"): + if "model name" in line: + cpu_name = re.sub( ".*model name.*:", "", line,1).strip() + except: + return "Unknown" + + return platform.machine() + ', ' + cpu_name + +def win_print_gpu_info(): + gpus = [] + gpu_memory = [] + + for i in range(0, 16): + try: + hHardwareReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "HARDWARE") + hDeviceMapReg = _winreg.OpenKey(hHardwareReg, "DEVICEMAP") + hVideoReg = _winreg.OpenKey(hDeviceMapReg, "VIDEO") + VideoCardString = _winreg.QueryValueEx(hVideoReg,"\Device\Video"+str(i))[0] + #Get Rid of Registry/Machine from the string + VideoCardStringSplit = VideoCardString.split("\\") + ClearnVideoCardString = string.join(VideoCardStringSplit[3:], "\\") + #Go up one level for detailed + VideoCardStringRoot = string.join(VideoCardStringSplit[3:len(VideoCardStringSplit)-1], "\\") + + #Get the graphics card information + hVideoCardReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, ClearnVideoCardString) + try: + VideoCardDescription = _winreg.QueryValueEx(hVideoCardReg, "Device Description")[0] + except WindowsError: + VideoCardDescription = _winreg.QueryValueEx(hVideoCardReg, "DriverDesc")[0] + + try: + driverVersion = _winreg.QueryValueEx(hVideoCardReg, "DriverVersion")[0] + VideoCardDescription += ', driver version ' + driverVersion + except: + pass + + try: + driverDate = _winreg.QueryValueEx(hVideoCardReg, "DriverDate")[0] + VideoCardDescription += ' (' + driverDate + ')' + except: + pass + + VideoCardMemorySize = _winreg.QueryValueEx(hVideoCardReg, "HardwareInformation.MemorySize")[0] + try: + vram = struct.unpack('l',VideoCardMemorySize)[0] + except struct.error: + vram = int(VideoCardMemorySize) + if not VideoCardDescription in gpus: + gpus += [VideoCardDescription] + gpu_memory += [str(int(vram/1024/1024))] + except WindowsError: + pass + + if len(gpus) == 1: + print "GPU: " + gpus[0] + " with " + gpu_memory[0] + " MB of VRAM" + elif len(gpus) > 1: + for i in range(0, len(gpus)): + print "GPU"+str(i)+ ": " + gpus[i] + " with " + gpu_memory[i] + " MBs of VRAM" + +def linux_print_gpu_info(): + glxinfo = subprocess.check_output('glxinfo') + for line in glxinfo.split("\n"): + if "OpenGL vendor string:" in line: + gl_vendor = line[len("OpenGL vendor string:"):].strip() + if "OpenGL version string:" in line: + gl_version = line[len("OpenGL version string:"):].strip() + if "OpenGL renderer string:" in line: + gl_renderer = line[len("OpenGL renderer string:"):].strip() + logi('GPU: ' + gl_vendor + ' ' + gl_renderer + ', GL version ' + gl_version) + +def osx_print_gpu_info(): + try: + info = subprocess.check_output(['system_profiler', 'SPDisplaysDataType']) + gpu = re.search("Chipset Model: (.*)", info) + if gpu: + chipset = gpu.group(1) + vram = re.search("VRAM \(Total\): (.*) MB", info) + if vram: + logi('GPU: ' + chipset + ' with ' + vram.group(1) + ' MBs of VRAM') + else: + logi('GPU: ' + chipset) + except: + pass + +def print_gpu_infolines(): + if WINDOWS: + win_print_gpu_info() + elif LINUX: + linux_print_gpu_info() + elif OSX: + osx_print_gpu_info() + +def get_executable_version(filename): + try: + if WINDOWS: + info = GetFileVersionInfo(filename, "\\") + ms = info['FileVersionMS'] + ls = info['FileVersionLS'] + version = HIWORD (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls) + return '.'.join(map(str, version)) + elif OSX: + plistfile = app_name[0:app_name.find('MacOS')] + 'Info.plist' + info = plistlib.readPlist(plistfile) + # Data in Info.plists is a bit odd, this check combo gives best information on each browser. + if 'firefox' in app_name.lower(): + return info['CFBundleShortVersionString'] + ' 20' + info['CFBundleVersion'][2:].replace('.', '-') + if 'opera' in app_name.lower(): + return info['CFBundleVersion'] + else: + return info['CFBundleShortVersionString'] + elif LINUX: + if 'firefox' in filename.lower(): + version = subprocess.check_output([filename, '-v']) + version = version.replace('Mozilla Firefox ', '') + return version.strip() + else: + return "" + except: + return "" + +# http://stackoverflow.com/questions/580924/python-windows-file-version-attribute +def win_get_file_properties(fname): + propNames = ('Comments', 'InternalName', 'ProductName', + 'CompanyName', 'LegalCopyright', 'ProductVersion', + 'FileDescription', 'LegalTrademarks', 'PrivateBuild', + 'FileVersion', 'OriginalFilename', 'SpecialBuild') + + props = {'FixedFileInfo': None, 'StringFileInfo': None, 'FileVersion': None} + + try: + # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc + fixedInfo = win32api.GetFileVersionInfo(fname, '\\') + props['FixedFileInfo'] = fixedInfo + props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536, + fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536, + fixedInfo['FileVersionLS'] % 65536) + + # \VarFileInfo\Translation returns list of available (language, codepage) + # pairs that can be used to retreive string info. We are using only the first pair. + lang, codepage = win32api.GetFileVersionInfo(fname, '\\VarFileInfo\\Translation')[0] + + # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle + # two are language/codepage pair returned from above + + strInfo = {} + for propName in propNames: + strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName) + ## print str_info + strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath) + + props['StringFileInfo'] = strInfo + except: + pass + + return props + +def get_os_version(): + try: + if WINDOWS: + versionHandle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion") + productName = _winreg.QueryValueEx(versionHandle, "ProductName") + return productName[0] + elif OSX: + return 'Mac OS ' + platform.mac_ver()[0] + elif LINUX: + kernel_version = subprocess.check_output(['uname', '-r']).strip() + return ' '.join(platform.linux_distribution()) + ', linux kernel ' + kernel_version + ' ' + platform.architecture()[0] + except: + return 'Unknown OS' + +def get_system_memory(): + try: + if WINDOWS: + return win32api.GlobalMemoryStatusEx()['TotalPhys'] + elif OSX: + return int(subprocess.check_output(['sysctl', '-n', 'hw.memsize']).strip()) + elif LINUX: + mem = open('/proc/meminfo', 'r') + lines = mem.readlines() + mem.close() + for i in lines: + sline = i.split() + if str(sline[0]) == 'MemTotal:': + return int(sline[1]) * 1024 + except: + return -1 + +# Finds the given executable 'program' in PATH. Operates like the Unix tool 'which'. +def which(program): + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + if WINDOWS and not '.' in fname: + if is_exe(exe_file + '.exe'): + return exe_file + '.exe' + if is_exe(exe_file + '.cmd'): + return exe_file + '.cmd' + if is_exe(exe_file + '.bat'): + return exe_file + '.bat' + + return None + +def win_get_default_browser(): + # Manually find the default system browser on Windows without relying on 'start %1' since + # that method has an issue, see comment below. + + # In Py3, this module is called winreg without the underscore + + with OpenKey(HKEY_CURRENT_USER, r"Software\Classes\http\shell\open\command") as key: + cmd = QueryValue(key, None) + if cmd: + parts = shlex.split(cmd) + if len(parts) > 0: + return [parts[0]] + + # Fall back to 'start %1', which we have to treat as if user passed --serve_forever, since + # for some reason, we are not able to detect when the browser closes when this is passed. + return ['cmd', '/C', 'start'] + +def find_browser(name): + if WINDOWS and name == 'start': + return win_get_default_browser() + if OSX and name == 'open': + return [name] + + if os.path.isfile(os.path.abspath(name)): + return [name] + if os.path.isfile(os.path.abspath(name)+'.exe'): + return [os.path.abspath(name)+'.exe'] + if os.path.isfile(os.path.abspath(name)+'.cmd'): + return [os.path.abspath(name)+'.cmd'] + if os.path.isfile(os.path.abspath(name)+'.bat'): + return [os.path.abspath(name)+'.bat'] + + path_lookup = which(name) + if path_lookup != None: + return [path_lookup] + + browser_locations = [] + if OSX: + # Note: by default Firefox beta installs as 'Firefox.app', you must manually rename it to + # FirefoxBeta.app after installation. + browser_locations = [ ('firefox', '/Applications/Firefox.app/Contents/MacOS/firefox'), + ('firefox_beta', '/Applications/FirefoxBeta.app/Contents/MacOS/firefox'), + ('firefox_aurora', '/Applications/FirefoxAurora.app/Contents/MacOS/firefox'), + ('firefox_nightly', '/Applications/FirefoxNightly.app/Contents/MacOS/firefox'), + ('safari', '/Applications/Safari.app/Contents/MacOS/Safari'), + ('opera', '/Applications/Opera.app/Contents/MacOS/Opera'), + ('chrome', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'), + ('chrome_canary', '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary') ] + elif WINDOWS: + pf_locations = ['ProgramFiles(x86)', 'ProgramFiles', 'ProgramW6432'] + + for pf_env in pf_locations: + if not pf_env in os.environ: + continue + program_files = os.environ[pf_env] if WINDOWS else '' + + browser_locations += [ ('chrome', os.path.join(program_files, 'Google/Chrome/Application/chrome.exe')), + ('chrome_canary', os.path.expanduser("~/AppData/Local/Google/Chrome SxS/Application/chrome.exe")), + ('firefox_nightly', os.path.join(program_files, 'Nightly/firefox.exe')), + ('firefox_aurora', os.path.join(program_files, 'Aurora/firefox.exe')), + ('firefox_beta', os.path.join(program_files, 'Beta/firefox.exe')), + ('firefox_beta', os.path.join(program_files, 'FirefoxBeta/firefox.exe')), + ('firefox_beta', os.path.join(program_files, 'Firefox Beta/firefox.exe')), + ('firefox', os.path.join(program_files, 'Mozilla Firefox/firefox.exe')), + ('iexplore', os.path.join(program_files, 'Internet Explorer/iexplore.exe')), + ('opera', os.path.join(program_files, 'Opera/launcher.exe')) ] + + elif LINUX: + browser_locations = [ ('firefox', os.path.expanduser('~/firefox/firefox')), + ('firefox_beta', os.path.expanduser('~/firefox_beta/firefox')), + ('firefox_aurora', os.path.expanduser('~/firefox_aurora/firefox')), + ('firefox_nightly', os.path.expanduser('~/firefox_nightly/firefox')), + ('chrome', which('google-chrome-stable'))] + + for (alias, browser_exe) in browser_locations: + if name == alias: + if os.path.isfile(browser_exe): + return [browser_exe] + + return None # Could not find the browser + +def browser_display_name(browser): + b = browser.lower() + if 'iexplore' in b: + return 'Microsoft Internet Explorer' + if 'chrome' in b: + return 'Google Chrome' + if 'firefox' in b: + # Try to identify firefox flavor explicitly, to help show issues where emrun would launch the wrong browser. + product_name = win_get_file_properties(browser)['StringFileInfo']['ProductName'] if WINDOWS else 'firefox' + if product_name.lower() != 'firefox': + return 'Mozilla Firefox ' + product_name + else: + return 'Mozilla Firefox' + if 'opera' in b: + return 'Opera' + if 'safari' in b: + return 'Apple Safari' + return browser + +def main(): + global browser_process, processname_killed_atexit, emrun_options, emrun_not_enabled_nag_printed + usage_str = "usage: %prog [options] [optional_portnum]" + parser = optparse.OptionParser(usage=usage_str) + + parser.add_option('--kill_start', dest='kill_on_start', action='store_true', default=False, + help='If true, any previously running instances of the target browser are killed before starting.') + + parser.add_option('--kill_exit', dest='kill_on_exit', action='store_true', default=False, + help='If true, the spawned browser process is forcibly killed when it calls exit().') + + parser.add_option('--no_server', dest='no_server', action='store_true', default=False, + help='If specified, a HTTP web server is not launched to host the page to run.') + + parser.add_option('--no_browser', dest='no_browser', action='store_true', default=False, + help='If specified, emrun will not launch a web browser to run the page.') + + parser.add_option('--no_emrun_detect', dest='no_emrun_detect', action='store_true', default=False, + help='If specified, skips printing the warning message if html page is detected to not have been built with --emrun linker flag.') + + parser.add_option('--serve_after_close', dest='serve_after_close', action='store_true', default=False, + help='If true, serves the web page even after the application quits by user closing the web page.') + + parser.add_option('--serve_after_exit', dest='serve_after_exit', action='store_true', default=False, + help='If true, serves the web page even after the application quits by a call to exit().') + + parser.add_option('--serve_root', dest='serve_root', default='', + help='If set, specifies the root path that the emrun web server serves. If not specified, the directory where the target .html page lives in is served.') + + parser.add_option('--verbose', dest='verbose', action='store_true', default=False, + help='Enable verbose logging from emrun internal operation.') + + parser.add_option('--port', dest='port', default=default_webserver_port, type="int", + help='Specifies the port the server runs in.') + + parser.add_option('--log_stdout', dest='log_stdout', default='', + help='Specifies a log filename where the browser process stdout data will be appended to.') + + parser.add_option('--log_stderr', dest='log_stderr', default='', + help='Specifies a log filename where the browser process stderr data will be appended to.') + + parser.add_option('--silence_timeout', dest='silence_timeout', type="int", default=0, + help='If no activity is received in this many seconds, the browser process is assumed to be hung, and the web server is shut down and the target browser killed. Disabled by default.') + + parser.add_option('--timeout', dest='timeout', type="int", default=0, + help='If the browser process does not quit or the page exit() in this many seconds, the browser is assumed to be hung, and the web server is shut down and the target browser killed. Disabled by default.') + + parser.add_option('--timeout_returncode', dest='timeout_returncode', type="int", default=99999, + help='Sets the exit code that emrun reports back to caller in the case that a page timeout occurs. Default: 99999.') + + parser.add_option('--list_browsers', dest='list_browsers', action='store_true', + help='Prints out all detected browser that emrun is able to use with the --browser command and exits.') + + parser.add_option('--browser', dest='browser', default='', + help='Specifies the browser executable to run the web page in.') + + parser.add_option('--system_info', dest='system_info', action='store_true', + help='Prints information about the current system at startup.') + + parser.add_option('--browser_info', dest='browser_info', action='store_true', + help='Prints information about the target browser to launch at startup.') + + parser.add_option('--log_html', dest='log_html', action='store_true', + help='If set, information lines are printed out an HTML-friendly format.') + + (options, args) = parser.parse_args(sys.argv) + emrun_options = options + + if not options.browser: + if WINDOWS: + options.browser = 'start' + elif LINUX: + options.browser = which('xdg-open') + if not options.browser: + options.browser = 'firefox' + elif OSX: + options.browser = 'safari' + + browsers = ['firefox', 'firefox_beta', 'firefox_aurora', 'firefox_nightly', 'chrome', 'chrome_canary', 'iexplore', 'safari', 'opera'] + if options.list_browsers: + logi('emrun has automatically found the following browsers in the default install locations on the system:') + logi('') + for browser in browsers: + browser_exe = find_browser(browser) + if type(browser_exe) == list: + browser_exe = browser_exe[0] + if browser_exe: + logi(' - ' + browser + ': ' + browser_display_name(browser_exe) + ' ' + get_executable_version(browser_exe)) + logi('') + logi('You can pass the --browser <id> option to launch with the given browser above.') + logi('Even if your browser was not detected, you can use --browser /path/to/browser/executable to launch with that browser.') + return + + if len(args) < 2 and (options.system_info or options.browser_info): + options.no_server = options.no_browser = True # Don't run if only --system_info or --browser_info was passed. + + if len(args) < 2 and not (options.no_server == True and options.no_browser == True): + logi('Usage: emrun filename.html') + return + + file_to_serve = args[1] if len(args) > 1 else '' + cmdlineparams = args[2:] if len(args) > 2 else [] + + if options.serve_root: + serve_dir = os.path.abspath(options.serve_root) + else: + serve_dir = os.path.dirname(os.path.abspath(file_to_serve)) + url = os.path.relpath(os.path.abspath(file_to_serve), serve_dir) + if len(cmdlineparams) > 0: + url += '?' + '&'.join(cmdlineparams) + url = 'http://localhost:'+str(options.port)+'/'+url + + os.chdir(serve_dir) + logv('Web server root directory: ' + os.path.abspath('.')) + + browser = find_browser(str(options.browser)) + browser_exe = browser[0] + browser_args = [] + + if 'safari' in browser_exe.lower(): + # Safari has a bug that a command line 'Safari http://page.com' does not launch that page, + # but instead launches 'file:///http://page.com'. To remedy this, must use the open -a command + # to run Safari, but unfortunately this will end up spawning Safari process detached from emrun. + if OSX: + browser = ['open', '-a', 'Safari'] + (browser[1:] if len(browser) > 1 else []) + + processname_killed_atexit = 'Safari' + elif 'chrome' in browser_exe.lower(): + processname_killed_atexit = 'chrome' + browser_args = ['--incognito', '--enable-nacl', '--enable-pnacl', '--disable-restore-session-state', '--enable-webgl', '--no-default-browser-check', '--no-first-run', '--allow-file-access-from-files'] +# if options.no_server: +# browser_args += ['--disable-web-security'] + elif 'firefox' in browser_exe.lower(): + processname_killed_atexit = 'firefox' + elif 'iexplore' in browser_exe.lower(): + processname_killed_atexit = 'iexplore' + browser_args = ['-private'] + elif 'opera' in browser_exe.lower(): + processname_killed_atexit = 'opera' + + # In Windows cmdline, & character delimits multiple commmands, so must use ^ to escape them. + if browser_exe == 'cmd': + url = url.replace('&', '^&') + browser += browser_args + [url] + + if options.kill_on_start: + kill_browser_process() + + if options.system_info: + logi('Time of run: ' + time.strftime("%x %X")) + logi('Computer name: ' + socket.gethostname()) # http://stackoverflow.com/questions/799767/getting-name-of-windows-computer-running-python-script + logi('OS: ' + get_os_version() + ' with ' + str(get_system_memory()/1024/1024) + ' MB of System RAM') + logi('CPU: ' + get_cpu_infoline()) + print_gpu_infolines() + if options.browser_info: + logi('Browser: ' + browser_display_name(browser[0]) + ' ' + get_executable_version(browser_exe)) + + # Suppress run warning if requested. + if options.no_emrun_detect: + emrun_not_enabled_nag_printed = True + + global browser_stdout_handle, browser_stderr_handle + if options.log_stdout: + browser_stdout_handle = open(options.log_stdout, 'ab') + if options.log_stderr: + if options.log_stderr == options.log_stdout: + browser_stderr_handle = browser_stdout_handle + else: + browser_stderr_handle = open(options.log_stderr, 'ab') + + if not options.no_browser: + logv("Executing %s" % ' '.join(browser)) + if browser[0] == 'cmd': + serve_forever = True # Workaround an issue where passing 'cmd /C start' is not able to detect when the user closes the page. + browser_process = subprocess.Popen(browser) + if options.kill_on_exit: + atexit.register(kill_browser_process) + + if not options.no_server: + logv('Starting web server in port ' + str(options.port)) + httpd = HTTPWebServer(('', options.port), HTTPHandler) + try: + httpd.serve_forever() + except KeyboardInterrupt: + httpd.server_close() + httpd.server_close() + + logv('Closed web server.') + + if not options.no_browser: + if options.kill_on_exit: + kill_browser_process() + elif is_browser_process_alive(): + logv('Not terminating browser process, pass --kill_exit to terminate the browser when it calls exit().') + + return page_exit_code + +if __name__ == '__main__': + sys.exit(main()) diff --git a/emrun.bat b/emrun.bat new file mode 100644 index 00000000..ae937e4d --- /dev/null +++ b/emrun.bat @@ -0,0 +1,2 @@ +@echo off +python "%~dp0\emrun" %*
\ No newline at end of file diff --git a/emscripten.py b/emscripten.py index 4fdf048e..111c2df4 100755 --- a/emscripten.py +++ b/emscripten.py @@ -726,7 +726,6 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, """ assert(settings['ASM_JS']) # TODO: apply ASM_JS even in -O0 for fastcomp - assert(settings['RUNNING_JS_OPTS']) # Overview: # * Run LLVM backend to emit JS. JS includes function bodies, memory initializer, @@ -741,9 +740,14 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, if DEBUG: shutil.copyfile(infile, os.path.join(shared.CANONICAL_TEMP_DIR, 'temp0.ll')) + extra_opt_args = [] + #if DEBUG: extra_opt_args.append('-time-passes') + + if DEBUG: t = time.time() + if DEBUG: logging.debug(' ..1..') temp1 = temp_files.get('.1.bc').name - shared.jsrun.timeout_run(subprocess.Popen([os.path.join(shared.LLVM_ROOT, 'opt'), infile, '-pnacl-abi-simplify-preopt', '-o', temp1])) + shared.jsrun.timeout_run(subprocess.Popen([os.path.join(shared.LLVM_ROOT, 'opt'), infile, '-pnacl-abi-simplify-preopt', '-o', temp1] + extra_opt_args)) assert os.path.exists(temp1) if DEBUG: shutil.copyfile(temp1, os.path.join(shared.CANONICAL_TEMP_DIR, 'temp1.bc')) @@ -760,19 +764,27 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, if DEBUG: logging.debug(' ..3..') temp3 = temp_files.get('.3.bc').name - shared.jsrun.timeout_run(subprocess.Popen([os.path.join(shared.LLVM_ROOT, 'opt'), temp2, '-pnacl-abi-simplify-postopt', '-o', temp3])) + shared.jsrun.timeout_run(subprocess.Popen([os.path.join(shared.LLVM_ROOT, 'opt'), temp2, '-pnacl-abi-simplify-postopt', '-o', temp3] + extra_opt_args)) #'-print-after-all' assert os.path.exists(temp3) if DEBUG: shutil.copyfile(temp3, os.path.join(shared.CANONICAL_TEMP_DIR, 'temp3.bc')) shared.jsrun.timeout_run(subprocess.Popen([os.path.join(shared.LLVM_ROOT, 'llvm-dis'), 'temp3.bc', '-o', 'temp3.ll'])) + if DEBUG: + logging.debug(' emscript: ir simplification took %s seconds' % (time.time() - t)) + t = time.time() + if DEBUG: logging.debug(' ..4..') temp4 = temp_files.get('.4.js').name backend_compiler = os.path.join(shared.LLVM_ROOT, 'llc') shared.jsrun.timeout_run(subprocess.Popen([backend_compiler, temp3, '-march=js', '-filetype=asm', '-o', temp4], stdout=subprocess.PIPE)) if DEBUG: shutil.copyfile(temp4, os.path.join(shared.CANONICAL_TEMP_DIR, 'temp4.js')) + if DEBUG: + logging.debug(' emscript: llvm backend took %s seconds' % (time.time() - t)) + t = time.time() + # Split up output backend_output = open(temp4).read() #if DEBUG: print >> sys.stderr, backend_output @@ -801,6 +813,20 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, table_sizes[k] = str(v.count(',')) # undercounts by one, but that is what we want funcs = re.sub(r"#FM_(\w+)#", lambda m: table_sizes[m.groups(0)[0]], funcs) + # fix +float into float.0, if not running js opts + if not settings['RUNNING_JS_OPTS']: + def fix_dot_zero(m): + num = m.group(3) + # TODO: handle 0x floats? + if num.find('.') < 0: + e = num.find('e'); + if e < 0: + num += '.0' + else: + num = num[:e] + '.0' + num[e:] + return m.group(1) + m.group(2) + num + funcs = re.sub(r'([(=,+\-*/%] *)\+(-?)((0x)?[0-9a-f]*\.?[0-9]+([eE][-+]?[0-9]+)?)', lambda m: fix_dot_zero(m), funcs) + # js compiler if DEBUG: logging.debug('emscript: js compiler glue') @@ -836,7 +862,9 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, assert '//FORWARDED_DATA:' in out, 'Did not receive forwarded data in pre output - process failed?' glue, forwarded_data = out.split('//FORWARDED_DATA:') - #print >> sys.stderr, out + if DEBUG: + logging.debug(' emscript: glue took %s seconds' % (time.time() - t)) + t = time.time() last_forwarded_json = forwarded_json = json.loads(forwarded_data) @@ -913,8 +941,13 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, Counter.i += 1 bad = 'b' + str(i) params = ','.join(['p%d' % p for p in range(len(sig)-1)]) + coerced_params = ','.join([shared.JS.make_coercion('p%d', sig[p+1], settings) % p for p in range(len(sig)-1)]) coercions = ';'.join(['p%d = %s' % (p, shared.JS.make_coercion('p%d' % p, sig[p+1], settings)) for p in range(len(sig)-1)]) + ';' - ret = '' if sig[0] == 'v' else ('return %s' % shared.JS.make_initializer(sig[0], settings)) + def make_func(name, code): + return 'function %s(%s) { %s %s }' % (name, params, coercions, code) + Counter.pre = [make_func(bad, ('abort' if not settings['ASSERTIONS'] else 'nullFunc') + '(' + str(i) + ');' + ( + '' if sig[0] == 'v' else ('return %s' % shared.JS.make_initializer(sig[0], settings)) + ))] start = raw.index('[') end = raw.rindex(']') body = raw[start+1:end].split(',') @@ -925,11 +958,23 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, Counter.j += 1 newline = Counter.j % 30 == 29 if item == '0': return bad if not newline else (bad + '\n') + if item not in metadata['implementedFunctions']: + # this is imported into asm, we must wrap it + call_ident = item + if call_ident in metadata['redirects']: call_ident = metadata['redirects'][call_ident] + if not call_ident.startswith('_') and not call_ident.startswith('Math_'): call_ident = '_' + call_ident + code = call_ident + '(' + coerced_params + ')' + if sig[0] != 'v': + code = 'return ' + shared.JS.make_coercion(code, sig[0], settings) + code += ';' + Counter.pre.append(make_func(item + '__wrapper', code)) + return item + '__wrapper' return item if not newline else (item + '\n') body = ','.join(map(fix_item, body)) - return ('function %s(%s) { %s %s(%d); %s }' % (bad, params, coercions, 'abort' if not settings['ASSERTIONS'] else 'nullFunc', i, ret), ''.join([raw[:start+1], body, raw[end:]])) + return ('\n'.join(Counter.pre), ''.join([raw[:start+1], body, raw[end:]])) infos = [make_table(sig, raw) for sig, raw in last_forwarded_json['Functions']['tables'].iteritems()] + Counter.pre = [] function_tables_defs = '\n'.join([info[0] for info in infos]) + '\n// EMSCRIPTEN_END_FUNCS\n' + '\n'.join([info[1] for info in infos]) @@ -1013,7 +1058,7 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, pass # If no named globals, only need externals global_vars = metadata['externs'] #+ forwarded_json['Variables']['globals'] - global_funcs = list(set(['_' + key for key, value in forwarded_json['Functions']['libraryFunctions'].iteritems() if value != 2]).difference(set(global_vars))) # + metadata['externFuncs']/'declares' + global_funcs = list(set(['_' + key for key, value in forwarded_json['Functions']['libraryFunctions'].iteritems() if value != 2]).difference(set(global_vars)).difference(set(metadata['implementedFunctions']))) def math_fix(g): return g if not g.startswith('Math_') else g.split('_')[1] asm_global_funcs = ''.join([' var ' + g.replace('.', '_') + '=global.' + g + ';\n' for g in maths]) + \ @@ -1189,6 +1234,8 @@ Runtime.stackRestore = function(top) { asm['stackRestore'](top) }; outfile.close() + if DEBUG: logging.debug(' emscript: final python processing took %s seconds' % (time.time() - t)) + if os.environ.get('EMCC_FAST_COMPILER'): emscript = emscript_fast diff --git a/src/analyzer.js b/src/analyzer.js index 253c5505..17582ea3 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1662,11 +1662,13 @@ function analyzer(data, sidePass) { function stackAnalyzer() { data.functions.forEach(function(func) { var lines = func.labels[0].lines; + var hasAlloca = false; for (var i = 0; i < lines.length; i++) { var item = lines[i]; if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.ident)) break; item.allocatedSize = func.variables[item.assignTo].impl === VAR_EMULATED ? calcAllocatedSize(item.allocatedType)*item.ident: 0; + hasAlloca = true; if (USE_TYPED_ARRAYS === 2) { // We need to keep the stack aligned item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN); @@ -1682,6 +1684,7 @@ function analyzer(data, sidePass) { } func.initialStack = index; func.otherStackAllocations = false; + if (func.initialStack === 0 && hasAlloca) func.otherStackAllocations = true; // a single alloca of zero still requires us to emit stack support code while (func.initialStack == 0) { // one-time loop with possible abort in the middle // If there is no obvious need for stack management, perhaps we don't need it // (we try to optimize that way with SKIP_STACK_IN_SMALL). However, diff --git a/src/emrun_postjs.js b/src/emrun_postjs.js new file mode 100644 index 00000000..e1ef9e2d --- /dev/null +++ b/src/emrun_postjs.js @@ -0,0 +1,20 @@ +function emrun_register_handlers() { + function post(msg) { + var http = new XMLHttpRequest(); + http.open("POST", "stdio.html", true); + http.send(msg); + } + // If the address contains localhost, we can assume we're running the test runner and should post stdout logs. + if (document.URL.search("localhost") != -1) { + var emrun_http_sequence_number = 1; + var prevExit = Module['exit']; + var prevPrint = Module['print']; + var prevErr = Module['printErr']; + Module['exit'] = function emrun_exit(returncode) { post('^exit^'+returncode); prevExit(returncode); } + Module['print'] = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+text); prevPrint(text); } + Module['printErr'] = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+text); prevErr(text); } + } + // Notify emrun web server that this browser has successfully launched the page. + post('^pageload^'); +} +emrun_register_handlers(); diff --git a/src/jsifier.js b/src/jsifier.js index b5502741..6b831b04 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1859,7 +1859,7 @@ function JSify(data, functionsOnly, givenFunctions) { // first row are utilities called from generated code, second are needed from fastLong ['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr', 'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) { - if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l')) { // TODO: one-by-one in fastcomp glue mode + if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l' && !addedLibraryItems[func])) { // TODO: one-by-one in fastcomp glue mode print(processLibraryFunction(LibraryManager.library[func], func)); // must be first to be close to generated code Functions.implementedFunctions['_' + func] = LibraryManager.library[func + '__sig']; Functions.libraryFunctions[func] = phase == 'glue' ? 2 : 1; // XXX diff --git a/src/library_fs.js b/src/library_fs.js index 5412185f..1e7856aa 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -961,7 +961,7 @@ mergeInto(LibraryManager.library, { throw new FS.ErrnoError(ERRNO_CODES.EACCES); } if (!stream.stream_ops.mmap) { - throw new FS.errnoError(ERRNO_CODES.ENODEV); + throw new FS.ErrnoError(ERRNO_CODES.ENODEV); } return stream.stream_ops.mmap(stream, buffer, offset, length, position, prot, flags); }, diff --git a/src/library_gl.js b/src/library_gl.js index cc39b048..29f78c8a 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -210,21 +210,30 @@ var LibraryGL = { }, get: function(name_, p, type) { + // Guard against user passing a null pointer. + // Note that GLES2 spec does not say anything about how passing a null pointer should be treated. + // Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but + // better to report an error instead of doing anything random. + if (!p) { +#if GL_ASSERTIONS + Module.printErr('GL_INVALID_VALUE in glGet' + type + 'v(name=' + name_ + ': Function called with null out pointer!'); +#endif + GL.recordError(0x0501 /* GL_INVALID_VALUE */); + return; + } var ret = undefined; switch(name_) { // Handle a few trivial GLES values case 0x8DFA: // GL_SHADER_COMPILER ret = 1; break; case 0x8DF8: // GL_SHADER_BINARY_FORMATS - if (type === 'Integer') { - // fall through, see gles2_conformance.cpp - } else { + if (type !== 'Integer') { GL.recordError(0x0500); // GL_INVALID_ENUM #if GL_ASSERTIONS Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(GL_SHADER_BINARY_FORMATS): Invalid parameter type!'); #endif - return; } + return; // Do not write anything to the out pointer, since no binary formats are supported. case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS ret = 0; break; diff --git a/src/library_glfw.js b/src/library_glfw.js index 647d4bb6..17e8956a 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -120,7 +120,6 @@ var LibraryGLFW = { if (event.charCode) { var char = GLFW.getUnicodeChar(event.charCode); if (char !== null && GLFW.charFunc) { - event.preventDefault(); Runtime.dynCall('vii', GLFW.charFunc, [event.charCode, 1]); } } @@ -130,13 +129,18 @@ var LibraryGLFW = { var key = GLFW.DOMToGLFWKeyCode(event.keyCode); if (key && GLFW.keyFunc) { GLFW.keys[key] = status; - event.preventDefault(); Runtime.dynCall('vii', GLFW.keyFunc, [key, status]); } }, onKeydown: function(event) { GLFW.onKeyChanged(event, 1);//GLFW_PRESS + // This logic comes directly from the sdl implementation. We cannot + // call preventDefault on all keydown events otherwise onKeyPress will + // not get called + if (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */) { + event.preventDefault(); + } }, onKeyup: function(event) { diff --git a/src/library_sdl.js b/src/library_sdl.js index 40e5e3ab..2efc1271 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1247,10 +1247,7 @@ var LibrarySDL = { return 0; }, - SDL_LowerBlit__deps: ['SDL_UpperBlit'], - SDL_LowerBlit: function(src, srcrect, dst, dstrect) { - return _SDL_UpperBlit(src, srcrect, dst, dstrect); - }, + SDL_LowerBlit: 'SDL_UpperBlit', SDL_FillRect: function(surf, rect, color) { var surfData = SDL.surfaces[surf]; diff --git a/src/modules.js b/src/modules.js index b9b8ab5e..3e7405f8 100644 --- a/src/modules.js +++ b/src/modules.js @@ -429,6 +429,26 @@ var LibraryManager = { eval(processMacros(preprocess(read(libraries[i])))); } + /* + // export code for CallHandlers.h + printErr('============================'); + for (var x in this.library) { + var y = this.library[x]; + if (typeof y === 'string' && x.indexOf('__sig') < 0 && x.indexOf('__postset') < 0 && y.indexOf(' ') < 0) { + printErr('DEF_REDIRECT_HANDLER(' + x + ', ' + y + ');'); + } + } + printErr('============================'); + for (var x in this.library) { + var y = this.library[x]; + if (typeof y === 'string' && x.indexOf('__sig') < 0 && x.indexOf('__postset') < 0 && y.indexOf(' ') < 0) { + printErr(' SETUP_CALL_HANDLER(' + x + ');'); + } + } + printErr('============================'); + // end export code for CallHandlers.h + */ + this.loaded = true; }, diff --git a/tests/cases/514_ta2.ll b/tests/cases/514_ta2.ll index ae60191c..ab363242 100644 --- a/tests/cases/514_ta2.ll +++ b/tests/cases/514_ta2.ll @@ -1,6 +1,6 @@ ; ModuleID = '/tmp/tmpxFUbAg/test_emcc1.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %struct.c_s = type { i8, float, i32 } diff --git a/tests/cases/aliasbitcast.ll b/tests/cases/aliasbitcast.ll index 70dc64ef..5e5f13aa 100644 --- a/tests/cases/aliasbitcast.ll +++ b/tests/cases/aliasbitcast.ll @@ -1,15 +1,15 @@ ; ModuleID = '/tmp/emscripten/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] -@_ZN16FormWidgetChoiceD2Ev = alias bitcast (i32 678 to i8*) ; [#uses=1] +@_ZN16FormWidgetChoiceD2Ev = alias i8* inttoptr (i32 678 to i8*) ; [#uses=1] ; [#uses=2] -define void @"\01_Z5hellov"() { +define void @"_Z5hellov"() { entry: - %0 = call i32 bitcast (i32 (i8*)* @puts to i32 (i32*)*)(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %0 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] br label %return return: ; preds = %entry @@ -25,7 +25,7 @@ entry: %retval = alloca i32 ; [#uses=2] %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] - call void @"\01_Z5hellov"() + call void @"_Z5hellov"() store i32 0, i32* %0, align 4 %1 = load i32* %0, align 4 ; [#uses=1] store i32 %1, i32* %retval, align 4 diff --git a/tests/cases/atomicrmw.ll b/tests/cases/atomicrmw.ll index fe479dce..31529250 100644 --- a/tests/cases/atomicrmw.ll +++ b/tests/cases/atomicrmw.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, %d,%d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -10,10 +10,10 @@ entry: %t = alloca i32, align 4 ; [#uses=2 type=i32**] store i32 50, i32* %t, align 4 %0 = load i32* %t - %1 = atomicrmw add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + %1 = atomicrmw add i32* %t, i32 3 seq_cst ; [#uses=0 type=i32] [debug line = 21:12] %2 = load i32* %t %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %2) ; [#uses=0 type=i32] - %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst ; [#uses=0 type=i32] [debug line = 21:12] ret i32 1 } diff --git a/tests/cases/atomicrmw_unaligned.ll b/tests/cases/atomicrmw_unaligned.ll index fe479dce..31529250 100644 --- a/tests/cases/atomicrmw_unaligned.ll +++ b/tests/cases/atomicrmw_unaligned.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, %d,%d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -10,10 +10,10 @@ entry: %t = alloca i32, align 4 ; [#uses=2 type=i32**] store i32 50, i32* %t, align 4 %0 = load i32* %t - %1 = atomicrmw add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + %1 = atomicrmw add i32* %t, i32 3 seq_cst ; [#uses=0 type=i32] [debug line = 21:12] %2 = load i32* %t %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %2) ; [#uses=0 type=i32] - %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst ; [#uses=0 type=i32] [debug line = 21:12] ret i32 1 } diff --git a/tests/cases/breakinthemiddle.ll b/tests/cases/breakinthemiddle.ll index 769b0e11..6e05b853 100644 --- a/tests/cases/breakinthemiddle.ll +++ b/tests/cases/breakinthemiddle.ll @@ -1,8 +1,11 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + @.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1] -define linkonce_odr i32* @main() align 2 { - %199 = trunc i8 1 to i1 ; [#uses=1] - br i1 %199, label %label555, label %label569 +define linkonce_odr i32 @main() align 2 { + %1 = trunc i8 1 to i1 ; [#uses=1] + br i1 %1, label %label555, label %label569 label555: ; preds = %353 br label %label569 @@ -10,7 +13,7 @@ label555: ; preds = %353 br label %label569 label569: ; preds = %555 - %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %3 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] ret i32 0 } diff --git a/tests/cases/breakinthemiddle2.ll b/tests/cases/breakinthemiddle2.ll index 318b49dc..ba96654f 100644 --- a/tests/cases/breakinthemiddle2.ll +++ b/tests/cases/breakinthemiddle2.ll @@ -1,21 +1,24 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + @.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1] define linkonce_odr i32 @main() align 2 { - %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] - %199 = trunc i8 1 to i1 ; [#uses=1] - br i1 %199, label %label555, label %label569 + %a333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %b199 = trunc i8 1 to i1 ; [#uses=1] + br i1 %b199, label %label555, label %label569 label555: ; preds = %0 br label %label569 ; branch should ignore all code after it in the block ; No predecessors! - %a472 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) + %aa472 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) cleanup - %a473 = extractvalue { i8*, i32 } %a472, 0 - %a474 = extractvalue { i8*, i32 } %a472, 1 + %aa473 = extractvalue { i8*, i32 } %aa472, 0 + %aa474 = extractvalue { i8*, i32 } %aa472, 1 br label %label569 label569: ; preds = %0 - br i1 %199, label %label990, label %label999 + br i1 %b199, label %label990, label %label999 label990: ret i32 0 ; ret should ignore all code after it in the block diff --git a/tests/cases/breakinthemiddle3.ll b/tests/cases/breakinthemiddle3.ll index e9173965..38da15ef 100644 --- a/tests/cases/breakinthemiddle3.ll +++ b/tests/cases/breakinthemiddle3.ll @@ -1,9 +1,12 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + @.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1] define linkonce_odr i32 @main() align 2 { - %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] - %199 = trunc i8 1 to i1 ; [#uses=1] - switch i32 %333, label %label999 [ + %a333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %z199 = trunc i8 1 to i1 ; [#uses=1] + switch i32 %a333, label %label999 [ i32 1000, label %label995 ] ; switch should ignore all code after it in the block ; No predecessors! @@ -14,7 +17,7 @@ define linkonce_odr i32 @main() align 2 { br label %label999 label995: - %333b = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %b333b = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] br label %label999 label999: ; preds = %555 diff --git a/tests/cases/caall.ll b/tests/cases/caall.ll index 5b8f7f29..2cc231ec 100644 --- a/tests/cases/caall.ll +++ b/tests/cases/caall.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -11,14 +11,14 @@ entry: store i32 0, i32* %retval %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] %call12 = call void (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 10) - %26 = load void (%class.Object*)** %call12 + %l26 = load void (i32*)** %call12 ret i32 1 } -define (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 %x) { +define void (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 %x) { entry: - %ret = inttoptr i32 0 to (i32*)** - ret (i32*)** %ret + %ret = inttoptr i32 0 to void (i32*)** + ret void (i32*)** %ret } ; [#uses=1] diff --git a/tests/cases/complexphi.ll b/tests/cases/complexphi.ll index fcb7185f..e79e6f1b 100644 --- a/tests/cases/complexphi.ll +++ b/tests/cases/complexphi.ll @@ -1,6 +1,6 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @_dispatchTable = internal global i64 0 @@ -21,8 +21,6 @@ cond.end: ; preds = %cond.false, %cond.t %cond = phi { i32, i32 } [ { i32 5, i32 6 }, %entry ], [ zeroinitializer, %cond.null ] ; [#uses=1] store { i32, i32 } %cond, { i32, i32 }* %comp - store { i32, i32 } { i32 ptrtoint (i64* @_dispatchTable to i32), i32 0 }, { i32, i32 }* getelementptr inbounds ([1 x i64]* @_dispatchTable, i32 0, i32 0, i32 1), align 4 - ret i32 0 ; [debug line = 6:13] } diff --git a/tests/cases/dash.ll b/tests/cases/dash.ll index ed5b01ae..6833a42e 100644 --- a/tests/cases/dash.ll +++ b/tests/cases/dash.ll @@ -1,6 +1,6 @@ ; ModuleID = '/tmp/tmpqfApGD/a.out.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @other-name = alias i32 ()* @main @@ -10,9 +10,9 @@ define i32 @main() { entry: %ret-val = alloca i32, align 4 store i32 0, i32* %ret-val - %aaa = bitcast i32 ()* @other-name to i32 + %aaa = ptrtoint i32 ()* @other-name to i32 %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.st-r, i32 0, i32 0), i32 %aaa) - ret i32 %ret-val + ret i32 0 } declare i32 @printf(i8*, ...) diff --git a/tests/cases/emptyalloca.ll b/tests/cases/emptyalloca.ll new file mode 100644 index 00000000..f12a4161 --- /dev/null +++ b/tests/cases/emptyalloca.ll @@ -0,0 +1,31 @@ +; ModuleID = '/tmp/tmpjSNiky/a.out.bc' +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + +@.str = private unnamed_addr constant [30 x i8] c"Module.print('hello, world!')\00", align 1 + +; Function Attrs: nounwind +define internal void @_Z9doNothingPi(i32* %arr) #0 { + %1 = alloca i32*, align 4 + store i32* %arr, i32** %1, align 4 + ret void +} + +define i32 @main() #1 { + %arr = alloca [0 x i32], align 4 + %1 = bitcast [0 x i32]* %arr to i8* + call void @llvm.memset.p0i8.i32(i8* %1, i8 0, i32 0, i32 4, i1 false) + %2 = getelementptr inbounds [0 x i32]* %arr, i32 0, i32 0 + call void @_Z9doNothingPi(i32* %2) + call void @emscripten_asm_const(i8* getelementptr inbounds ([30 x i8]* @.str, i32 0, i32 0)) + ret i32 0 +} + +; Function Attrs: nounwind +declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #2 + +declare void @emscripten_asm_const(i8*) #1 + +attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind } diff --git a/tests/cases/emptyasm_le32.ll b/tests/cases/emptyasm_le32.ll index e123d3d5..8f6b606e 100644 --- a/tests/cases/emptyasm_le32.ll +++ b/tests/cases/emptyasm_le32.ll @@ -1,3 +1,6 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + ; ModuleID = 'tests/hello_world.bc' @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -7,7 +10,7 @@ define i32 @main() { entry: %retval = alloca i32, align 4 ; [#uses=1 type=i32*] store i32 0, i32* %retval - call void asm sideeffect "", "~{memory}"() nounwind, !srcloc !0 + call void asm sideeffect "", "~{memory}"() nounwind %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] ret i32 1 } diff --git a/tests/cases/entry3.ll b/tests/cases/entry3.ll index a20c6843..6888d0a8 100644 --- a/tests/cases/entry3.ll +++ b/tests/cases/entry3.ll @@ -1,25 +1,25 @@ ; ModuleID = '/tmp/tmpKnA2D3/a.out.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [11 x i8] c"getgid=%d\0A\00", align 1 @.str1 = private unnamed_addr constant [6 x i8] c"f=%d\0A\00", align 1 define internal i32 @_Z1fii(i32, i32) noinline { entry: - %3 = tail call i32 @getgid() - %4 = icmp eq i32 %3, 0 - br i1 %4, label %cond.b, label %cond.a + %a3 = tail call i32 @getgid() + %a4 = icmp eq i32 %a3, 0 + br i1 %a4, label %cond.b, label %cond.a cond.a: - %6 = tail call i32 @getgid() + %a6 = tail call i32 @getgid() br label %cond.end cond.b: br label %cond.end cond.end: - %.0 = phi i32 [ 0, %cond.b ], [ 1, %1 ] + %.0 = phi i32 [ 0, %cond.b ], [ 1, %cond.a ] ret i32 %.0 } diff --git a/tests/cases/funcptr.ll b/tests/cases/funcptr.ll index 0aa03fcf..ef869c33 100644 --- a/tests/cases/funcptr.ll +++ b/tests/cases/funcptr.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [17 x i8] c"hello %d world!\0A\00", align 1 ; [#uses=1 type=[17 x i8]*] @@ -9,7 +9,7 @@ define i32 @main() { entry: %retval = alloca i32, align 4 ; [#uses=1 type=i32*] store i32 0, i32* %retval - %access_virt_barray = bitcast i32 100 to [64 x i16]* (i32*, i32)** + %access_virt_barray = inttoptr i32 100 to [64 x i16]* (i32*, i32)** store [64 x i16]* (i32*, i32)* @access_virt_barray, [64 x i16]* (i32*, i32)** %access_virt_barray, align 4 %wakaptr = bitcast [64 x i16]* (i32*, i32)** %access_virt_barray to i32* %waka = load i32* %wakaptr @@ -20,7 +20,7 @@ entry: } define [64 x i16]* @access_virt_barray(i32*, i32) { - ret void + ret [64 x i16]* inttoptr (i32 0 to [64 x i16]*) } ; [#uses=1] diff --git a/tests/cases/i24_mem_ta2.ll b/tests/cases/i24_mem_ta2.ll index e50014ca..550389fe 100644 --- a/tests/cases/i24_mem_ta2.ll +++ b/tests/cases/i24_mem_ta2.ll @@ -1,8 +1,8 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" -@.str = private unnamed_addr constant [15 x i8] c".%x.\0A\00", align 1 ; [#uses=1 type=[5 x i8]*] +@.str = private unnamed_addr constant [6 x i8] c".%x.\0A\00", align 1 ; [#uses=1 type=[5 x i8]*] define i32 @main() { entry: @@ -11,11 +11,11 @@ entry: %i24 = bitcast i32* %mem to i24* %load = load i24* %i24, align 4 %load32 = zext i24 %load to i32 - %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 %load32) + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i32 %load32) %val_24 = trunc i32 4041265344 to i24 store i24 %val_24, i24* %i24, align 4 %load32b = load i32* %mem, align 4 - %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 %load32b) + %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i32 %load32b) ret i32 1 } diff --git a/tests/cases/i64toi8star.ll b/tests/cases/i64toi8star.ll index d4a39340..b2307449 100644 --- a/tests/cases/i64toi8star.ll +++ b/tests/cases/i64toi8star.ll @@ -25,8 +25,8 @@ entry: %retval = alloca i32 ; [#uses=2] %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] - %5 = call i32 @PyLong_FromVoidPtr(i8* null) nounwind ; [#uses=0] - %13 = call i32 @PyLong_FromVoidPtr(i8* inttoptr (i64 1 to i8*)) nounwind ; [#uses=0] - %1 = call i32 bitcast (i32 (i8*)* @puts to i32 (i32*)*)(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %a5 = call i32 @PyLong_FromVoidPtr(i8* null) nounwind ; [#uses=0] + %a13 = call i32 @PyLong_FromVoidPtr(i8* inttoptr (i64 1 to i8*)) nounwind ; [#uses=0] + %a1 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] ret i32 0 } diff --git a/tests/cases/inttoptr.ll b/tests/cases/inttoptr.ll index b0711672..c1b40a74 100644 --- a/tests/cases/inttoptr.ll +++ b/tests/cases/inttoptr.ll @@ -1,6 +1,6 @@ ; ModuleID = '/tmp/emscripten/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] @@ -14,7 +14,7 @@ entry: %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] %sz.i7 = inttoptr i32 64 to i32* ; [#uses=1 type=i32*] - store i32 184, i32* %sz.i7, align 8, !tbaa !1610 - %1 = call i32 bitcast (i32 (i8*)* @puts to i32 (i32*)*)(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + store i32 184, i32* %sz.i7, align 8 + %1 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] ret i32 0 } diff --git a/tests/cases/invokebitcast.ll b/tests/cases/invokebitcast.ll index ffb5803f..ec090b0d 100644 --- a/tests/cases/invokebitcast.ll +++ b/tests/cases/invokebitcast.ll @@ -1,7 +1,7 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' ; Just test for compilation here -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-f128:128:128-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %struct.CPU_Regs = type { [8 x %union.GenReg32] } %union.GenReg32 = type { [1 x i32] } @@ -16,7 +16,8 @@ entry: %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] %1 = load i32* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i32*), align 2 ; [#uses=1] - store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 + %s = trunc i32 %1 to i16 + store i16 %s, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 %2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] store i32 0, i32* %0, align 4 %3 = load i32* %0, align 4 ; [#uses=1] diff --git a/tests/cases/invokeundef.ll b/tests/cases/invokeundef.ll index 9dc1f93d..be1dd671 100644 --- a/tests/cases/invokeundef.ll +++ b/tests/cases/invokeundef.ll @@ -1,7 +1,7 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' ; Just test for compilation here -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-f128:128:128-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %struct.CPU_Regs = type { [8 x %union.GenReg32] } %union.GenReg32 = type { [1 x i32] } @@ -16,14 +16,15 @@ entry: %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] %1 = load i32* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i32*), align 2 ; [#uses=1] - store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 + %a1 = trunc i32 %1 to i16 + store i16 %a1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 %2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] store i32 0, i32* %0, align 4 %3 = load i32* %0, align 4 ; [#uses=1] store i32 %3, i32* %retval, align 4 br label %return - invoke void undef(%struct.CPU_Regs* noalias @cpu_regs, i32 %99) + invoke void undef(%struct.CPU_Regs* noalias @cpu_regs, i32 0) to label %invcont33 unwind label %lpad106 invcont33: diff --git a/tests/cases/legalizer_ta2.ll b/tests/cases/legalizer_ta2.ll index 89ebcef6..6f153ad2 100644 --- a/tests/cases/legalizer_ta2.ll +++ b/tests/cases/legalizer_ta2.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @globaliz = global [300 x i8] zeroinitializer diff --git a/tests/cases/loadbitcastgep.ll b/tests/cases/loadbitcastgep.ll index 2a90dbb7..cfb88a0d 100644 --- a/tests/cases/loadbitcastgep.ll +++ b/tests/cases/loadbitcastgep.ll @@ -1,6 +1,6 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-f128:128:128-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %struct.CPU_Regs = type { [8 x %union.GenReg32] } %union.GenReg32 = type { [1 x i32] } @@ -15,7 +15,8 @@ entry: %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] %1 = load i32* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i32*), align 2 ; [#uses=1] - store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 + %b = trunc i32 %1 to i16 + store i16 %b, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 %2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] store i32 0, i32* %0, align 4 %3 = load i32* %0, align 4 ; [#uses=1] diff --git a/tests/cases/oob_ta2.ll b/tests/cases/oob_ta2.ll index 3c94c13c..b95d28da 100644 --- a/tests/cases/oob_ta2.ll +++ b/tests/cases/oob_ta2.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %structy = type { [2 x [10 x i8]] } diff --git a/tests/cases/phi24_ta2.ll b/tests/cases/phi24_ta2.ll index 2d9b6646..18577fee 100644 --- a/tests/cases/phi24_ta2.ll +++ b/tests/cases/phi24_ta2.ll @@ -1,9 +1,6 @@ -;;; trunc i32 into i24, needs $0 on target variable name - -; ModuleID = '/tmp/tmpvqlBv2/a.out.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %union.U4 = type { i32 } %union.U3 = type { i8* } diff --git a/tests/cases/phicubed.ll b/tests/cases/phicubed.ll index a0799997..5fc3208b 100644 --- a/tests/cases/phicubed.ll +++ b/tests/cases/phicubed.ll @@ -1,4 +1,6 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" %struct.worker_args = type { i32, %struct.worker_args* } diff --git a/tests/cases/phientryimplicit.ll b/tests/cases/phientryimplicit.ll index 8a510f43..b7b17add 100644 --- a/tests/cases/phientryimplicit.ll +++ b/tests/cases/phientryimplicit.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" ; Phi nodes can refer to the entry. And the entry might be unnamed, and doesn't even have a consistent implicit name! @@ -9,35 +9,35 @@ target triple = "i386-pc-linux-gnu" ; [#uses=0] define i32 @main() { %retval = alloca i32, align 4 ; [#uses=1 type=i32*] - %16 = trunc i32 1 to i1 - br i1 %16, label %17, label %26, !dbg !1269853 ; [debug line = 3920:5] + %a16 = trunc i32 1 to i1 + br i1 %a16, label %L17, label %L26, !dbg !1269853 ; [debug line = 3920:5] -; <label>:17 ; preds = %1 - %25 = trunc i32 1 to i1 - br label %26 +L17: + %a25 = trunc i32 1 to i1 + br label %L26 -; <label>:26 ; preds = %17, %1 - %27 = phi i1 [ false, %1 ], [ %25, %17 ] ; [#uses=1 type=i1] +L26: + %a27 = phi i1 [ false, %1 ], [ %25, %L17 ] ; [#uses=1 type=i1] store i32 0, i32* %retval %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] - %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %27) ; make sure %27 is used + %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i1 %a27) ; make sure %27 is used ret i32 1 } define i32 @main0() { %retval = alloca i32, align 4 ; [#uses=1 type=i32*] - %16 = trunc i32 1 to i1 - br i1 %16, label %17, label %26, !dbg !1269853 ; [debug line = 3920:5] + %a16 = trunc i32 1 to i1 + br i1 %a16, label %L17, label %L26, !dbg !1269853 ; [debug line = 3920:5] -; <label>:17 ; preds = %1 - %25 = trunc i32 1 to i1 - br label %26 +L17: + %a25 = trunc i32 1 to i1 + br label %L26 -; <label>:26 ; preds = %17, %1 - %27 = phi i1 [ false, %0 ], [ %25, %17 ] ; [#uses=1 type=i1] +L26: + %a27 = phi i1 [ false, %0 ], [ %25, %L17 ] ; [#uses=1 type=i1] store i32 0, i32* %retval %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] - %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %27) ; make sure %27 is used + %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i1 %a27) ; make sure %27 is used ret i32 1 } diff --git a/tests/cases/phientryimplicitmix.ll b/tests/cases/phientryimplicitmix.ll index 9223c059..527c761f 100644 --- a/tests/cases/phientryimplicitmix.ll +++ b/tests/cases/phientryimplicitmix.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" ; Phi nodes can refer to the entry. And the entry might be unnamed, and doesn't even have a consistent implicit name! @@ -9,20 +9,20 @@ target triple = "i386-pc-linux-gnu" ; [#uses=0] define i32 @main() { %retval = alloca i32, align 4 ; [#uses=1 type=i32*] - %16 = trunc i32 1 to i1 - br i1 %16, label %whoosh, label %26, !dbg !1269853 ; [debug line = 3920:5] + %1 = trunc i32 1 to i1 + br i1 %1, label %whoosh, label %L26 whoosh: ; preds = %1 - %25 = trunc i32 1 to i1 - br label %26 + %a25 = trunc i32 1 to i1 + br label %L26 -; <label>:26 ; preds = %17, %1 - %27 = phi i1 [ false, %1 ], [ %25, %whoosh ] ; [#uses=1 type=i1] - %28 = phi i1 [ true, %1 ], [ %25, %whoosh ] ; [#uses=1 type=i1] +L26: + %a27 = phi i1 [ false, %0 ], [ true, %whoosh ] ; [#uses=1 type=i1] + %a28 = phi i1 [ true, %0 ], [ false, %whoosh ] ; [#uses=1 type=i1] store i32 0, i32* %retval %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] - %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %27) ; make sure %27 is used - %cal3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %28) ; make sure %28 is used + %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i1 %a27) ; make sure %27 is used + %cal3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i1 %a28) ; make sure %28 is used ret i32 1 } diff --git a/tests/cases/phientryimplicitmoar.ll b/tests/cases/phientryimplicitmoar.ll index c83458e6..0f07cc44 100644 --- a/tests/cases/phientryimplicitmoar.ll +++ b/tests/cases/phientryimplicitmoar.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @.str2 = private unnamed_addr constant [15 x i8] c"hello!!world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -9,16 +9,16 @@ define i32 @main() { %retval = alloca i32, align 4 %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str2, i32 0, i32 0)) %a12 = zext i1 1 to i32 - br label %13 + br label %L13 -; <label>:13 ; preds = %13, %1 - %a14 = phi i32 [ %a12, %1 ], [ %a15, %13 ] +L13: + %a14 = phi i32 [ %a12, %0 ], [ %a15, %L13 ] %call0 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) %a15 = add nsw i32 %a14, 2 %a16 = icmp eq i32 %a15, 9 - br i1 %a16, label %17, label %13 + br i1 %a16, label %L17, label %L13 -; <label>:17 ; preds = %1 +L17: %call1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str2, i32 0, i32 0)) ret i32 1 } diff --git a/tests/cases/phiself.ll b/tests/cases/phiself.ll index 81249799..0a06fcca 100644 --- a/tests/cases/phiself.ll +++ b/tests/cases/phiself.ll @@ -1,6 +1,6 @@ ; ModuleID = '/tmp/emscripten_temp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [7 x i8] c"cheez\0A\00", align 1 @.str1 = private unnamed_addr constant [6 x i8] c"*%d*\0A\00", align 1 diff --git a/tests/cases/ptrtoi64.ll b/tests/cases/ptrtoi64.ll index 01e466fe..5898f529 100644 --- a/tests/cases/ptrtoi64.ll +++ b/tests/cases/ptrtoi64.ll @@ -1,8 +1,8 @@ ; pointer to i64, then to i32 ; ModuleID = '/tmp/emscripten/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str2 = private constant [9 x i8] c"*%d,%d*\0A\00", align 1 ; [#uses=1] @@ -18,10 +18,10 @@ entry: %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] %sz.i7 = inttoptr i32 400 to i32* ; [#uses=1 type=i32*] - %10 = ptrtoint i32* %sz.i7 to i64, !dbg !8557 ; [#uses=1 type=i64] [debug line = 99:3] - %conv5 = trunc i64 %10 to i32, !dbg !8557 ; [#uses=1 type=i32] [debug line = 99:3] - %11 = ptrtoint i32* %sz.i7 to i8, !dbg !8557 ; [#uses=1 type=i64] [debug line = 99:3] - %conv6 = zext i8 %11 to i32, !dbg !8557 ; [#uses=1 type=i32] [debug line = 99:3] - %55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %conv5, i32 %conv6) ; [#uses=0] + %a10 = ptrtoint i32* %sz.i7 to i64 + %conv5 = trunc i64 %a10 to i32 + %a11 = ptrtoint i32* %sz.i7 to i8 + %conv6 = zext i8 %a11 to i32 + %a55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %conv5, i32 %conv6) ret i32 0 } diff --git a/tests/cases/selectstruct.ll b/tests/cases/selectstruct.ll index 5c9fecf7..58b1848e 100644 --- a/tests/cases/selectstruct.ll +++ b/tests/cases/selectstruct.ll @@ -8,7 +8,9 @@ target triple = "i386-pc-linux-gnu" define i32 @main() { entry: %retval = alloca i32, align 4 ; [#uses=1 type=i32*] - %. = select i1 %retval, { i32, i32 } { i32 55, i32 99 }, { i32, i32 } { i32 2, i32 6 } ; [#uses=1 type={ i32, i32 }] + %check = ptrtoint i32* %retval to i32 + %check1 = trunc i32 %check to i1 + %. = select i1 %check1, { i32, i32 } { i32 55, i32 99 }, { i32, i32 } { i32 2, i32 6 } ; [#uses=1 type={ i32, i32 }] store i32 0, i32* %retval %.1 = extractvalue { i32, i32 } %., 0 %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %.1) ; [#uses=0 type=i32] diff --git a/tests/cases/sillybitcast.ll b/tests/cases/sillybitcast.ll index c5ca4f9a..50a54da9 100644 --- a/tests/cases/sillybitcast.ll +++ b/tests/cases/sillybitcast.ll @@ -1,6 +1,6 @@ ; ModuleID = '/tmp/emscripten/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] diff --git a/tests/cases/sillybitcast2.ll b/tests/cases/sillybitcast2.ll new file mode 100644 index 00000000..02cf8615 --- /dev/null +++ b/tests/cases/sillybitcast2.ll @@ -0,0 +1,35 @@ +; ModuleID = '/tmp/emscripten/tmp/src.cpp.o' +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + +@.str = private constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] + +; [#uses=2] +define void @"_Z5hellov"() { +entry: + %0 = call i32 bitcast (i32 (i32*)* @puts to i32 (i8*)*)(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + br label %return + +return: ; preds = %entry + ret void +} + +; [#uses=1] +declare i32 @puts(i32*) + +; [#uses=0] +define i32 @main() { +entry: + %retval = alloca i32 ; [#uses=2] + %0 = alloca i32 ; [#uses=2] + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + call void @"_Z5hellov"() + store i32 0, i32* %0, align 4 + %1 = load i32* %0, align 4 ; [#uses=1] + store i32 %1, i32* %retval, align 4 + br label %return + +return: ; preds = %entry + %retval1 = load i32* %retval ; [#uses=1] + ret i32 %retval1 +} diff --git a/tests/cases/sillyfuncast.ll b/tests/cases/sillyfuncast.ll index 36c26720..33598104 100644 --- a/tests/cases/sillyfuncast.ll +++ b/tests/cases/sillyfuncast.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @@ -13,7 +13,7 @@ define i32 @main() { entry: %retval = alloca i32, align 4 ; [#uses=1 type=i32*] store i32 0, i32* %retval - %58 = tail call i32 bitcast (void ()* @doit to i32 ()*)() nounwind + %0 = tail call i32 bitcast (void ()* @doit to i32 ()*)() nounwind ret i32 1 } diff --git a/tests/cases/storebigfloat.ll b/tests/cases/storebigfloat.ll index c9995835..b940f5ca 100644 --- a/tests/cases/storebigfloat.ll +++ b/tests/cases/storebigfloat.ll @@ -1,3 +1,5 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] diff --git a/tests/cases/storestruct.ll b/tests/cases/storestruct.ll index a5b7483b..3e996195 100644 --- a/tests/cases/storestruct.ll +++ b/tests/cases/storestruct.ll @@ -1,6 +1,6 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" ; Load and store an entire structure as a whole (and also load as a whole, extract values and save separately, etc.) @@ -43,7 +43,11 @@ entry: %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i32 %tmp5, i32 %tmp6), !dbg !18 ; [#uses=0] %ptr = inttoptr i32 52 to i32* ; [#uses=1] - store %struct.X { i32 ptrtoint (i32* getelementptr inbounds (i32* %ptr, i32 1, i32 0) to i32), i32 3 }, %struct.X* %y, align 4 ; store entire struct at once + %ptrgep = getelementptr inbounds i32* %ptr, i32 1 + %ptrgepint = ptrtoint i32* %ptrgep to i32 + %ss1 = insertvalue %struct.X undef, i32 %ptrgepint, 0 + %ss2 = insertvalue %struct.X %ss1, i32 3, 1 + store %struct.X %ss2, %struct.X* %y, align 4 ; store entire struct at once %tmp5b = load i32* %a1, align 4, !dbg !18 ; [#uses=1] %tmp6b = load i32* %b2, align 4, !dbg !18 ; [#uses=1] diff --git a/tests/cases/structphiparam.ll b/tests/cases/structphiparam.ll index 117bdf77..fadf4d29 100644 --- a/tests/cases/structphiparam.ll +++ b/tests/cases/structphiparam.ll @@ -1,6 +1,6 @@ ; ModuleID = '/dev/shm/tmp/src.cpp.o' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, %d %d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] @_dispatchTable = internal global i64 0 diff --git a/tests/cases/sub_11_0.ll b/tests/cases/sub_11_0.ll index 7f0bb285..d4094556 100644 --- a/tests/cases/sub_11_0.ll +++ b/tests/cases/sub_11_0.ll @@ -1,4 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] diff --git a/tests/cases/switch64_ta2.ll b/tests/cases/switch64_ta2.ll index e56ccfba..4d5c6273 100644 --- a/tests/cases/switch64_ta2.ll +++ b/tests/cases/switch64_ta2.ll @@ -1,10 +1,13 @@ +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + @.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1] define linkonce_odr i32 @main() align 2 { - %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] - %444 = zext i32 %333 to i64 - %199 = trunc i8 1 to i1 ; [#uses=1] - switch i64 %444, label %label999 [ + %a333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %a444 = zext i32 %a333 to i64 + %a199 = trunc i8 1 to i1 ; [#uses=1] + switch i64 %a444, label %label999 [ i64 1000, label %label9950 i64 1001, label %label9951 i64 1002, label %label9952 @@ -24,7 +27,7 @@ define linkonce_odr i32 @main() align 2 { br label %label999 label9950: - %333b = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %a333b = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] br label %label999 label9951: diff --git a/tests/cases/uadd_overflow_ta2.ll b/tests/cases/uadd_overflow_ta2.ll index feac60e3..e827cb38 100644 --- a/tests/cases/uadd_overflow_ta2.ll +++ b/tests/cases/uadd_overflow_ta2.ll @@ -1,6 +1,6 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str2 = private constant [9 x i8] c"*%d,%d*\0A\00", align 1 ; [#uses=1] @@ -24,14 +24,14 @@ entry: %ba2 = zext i1 %ba1 to i32 call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %ba0, i32 %ba2) ; [#uses=0] - %64buadd1pre = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 5000, i64 3000) - %64buadd1 = insertvalue { i64, i1 } %64buadd1pre, i64 9875, 0 - %64buadd2 = insertvalue { i64, i1 } %64buadd1, i1 1, 1 - %64ba0pre = extractvalue { i64, i1 } %64buadd2, 0 - %64ba0 = trunc i64 %64ba0pre to i32 - %64ba1 = extractvalue { i64, i1 } %64buadd2, 1 - %64ba2 = zext i1 %64ba1 to i32 - call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %64ba0, i32 %64ba2) ; [#uses=0] + %z64buadd1pre = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 5000, i64 3000) + %z64buadd1 = insertvalue { i64, i1 } %z64buadd1pre, i64 9875, 0 + %z64buadd2 = insertvalue { i64, i1 } %z64buadd1, i1 1, 1 + %z64ba0pre = extractvalue { i64, i1 } %z64buadd2, 0 + %z64ba0 = trunc i64 %z64ba0pre to i32 + %z64ba1 = extractvalue { i64, i1 } %z64buadd2, 1 + %z64ba2 = zext i1 %z64ba1 to i32 + call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %z64ba0, i32 %z64ba2) ; [#uses=0] %zbuadd1 = insertvalue { i32, i1 } { i32 undef, i1 false }, i32 10, 0 ; undef and explicit %zba0 = extractvalue { i32, i1 } %zbuadd1, 0 @@ -46,5 +46,5 @@ entry: declare i32 @printf(i8*, ...) declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone -declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i32) nounwind readnone +declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone diff --git a/tests/cases/unaligneddouble.ll b/tests/cases/unaligneddouble.ll index 22b92741..e4067831 100644 --- a/tests/cases/unaligneddouble.ll +++ b/tests/cases/unaligneddouble.ll @@ -10,7 +10,7 @@ entry: %retval = alloca i32, align 4 ; [#uses=1 type=i32*] %doub = alloca double, align 4 store i32 0, i32* %retval - %0 = bitcast double* %doub to i32 + %0 = ptrtoint double* %doub to i32 %1 = uitofp i32 %0 to double store double %1, double* %doub, align 1 store double %1, double* %doub, align 2 diff --git a/tests/cases/zeroembedded.ll b/tests/cases/zeroembedded.ll index 6a4f6073..167fe278 100644 --- a/tests/cases/zeroembedded.ll +++ b/tests/cases/zeroembedded.ll @@ -1,4 +1,6 @@ -; a.ll +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + %struct.pypy_str = type { i32, [0 x i8] } %struct.pypy_strval = type { i32, [13 x i8] } diff --git a/tests/cases/zeroextarg.ll b/tests/cases/zeroextarg.ll index 25efb7ec..a3caa74c 100644 --- a/tests/cases/zeroextarg.ll +++ b/tests/cases/zeroextarg.ll @@ -1,10 +1,10 @@ ; ModuleID = 'tests/hello_world.bc' -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" -target triple = "i386-pc-linux-gnu" +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" @.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] -define void @glSampleCoverage(float %18, i8 zeroext %invert) { +define void @glSampleCoverage(float %a18, i8 zeroext %invert) { entry: %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] ret void diff --git a/tests/core/test_addr_of_stacked.in b/tests/core/test_addr_of_stacked.in index af5a6e32..7a4d9ba7 100644 --- a/tests/core/test_addr_of_stacked.in +++ b/tests/core/test_addr_of_stacked.in @@ -1,14 +1,8 @@ - - #include <stdio.h> - void alter(int *y) - { - *y += 5; - } - int main() - { - int x = 2; - alter(&x); - printf("*%d*\n", x); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +void alter(int *y) { *y += 5; } +int main() { + int x = 2; + alter(&x); + printf("*%d*\n", x); + return 0; +} diff --git a/tests/core/test_alloca.in b/tests/core/test_alloca.in index 7b53e56c..bfad3324 100644 --- a/tests/core/test_alloca.in +++ b/tests/core/test_alloca.in @@ -1,11 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main() { - char *pc; - pc = (char *)alloca(5); - printf("z:%d*%d*\n", pc > 0, (int)pc); - return 0; - } -
\ No newline at end of file +int main() { + char *pc; + pc = (char *)alloca(5); + printf("z:%d*%d*\n", pc > 0, (int)pc); + return 0; +} diff --git a/tests/core/test_alloca_stack.in b/tests/core/test_alloca_stack.in index ab7c7306..ba3afcc7 100644 --- a/tests/core/test_alloca_stack.in +++ b/tests/core/test_alloca_stack.in @@ -1,19 +1,16 @@ - // We should not blow up the stack with numerous allocas - #include <stdio.h> - #include <stdlib.h> +#include <stdio.h> +#include <stdlib.h> - func(int i) { - char *pc = (char *)alloca(100); - *pc = i; - (*pc)++; - return (*pc) % 10; - } - int main() { - int total = 0; - for (int i = 0; i < 1024*1024; i++) - total += func(i); - printf("ok:%d*\n", total); - return 0; - } - +func(int i) { + char *pc = (char *)alloca(100); + *pc = i; + (*pc)++; + return (*pc) % 10; +} +int main() { + int total = 0; + for (int i = 0; i < 1024 * 1024; i++) total += func(i); + printf("ok:%d*\n", total); + return 0; +} diff --git a/tests/core/test_array2.in b/tests/core/test_array2.in index 0e5bcbfb..452e0792 100644 --- a/tests/core/test_array2.in +++ b/tests/core/test_array2.in @@ -1,15 +1,13 @@ +#include <stdio.h> - #include <stdio.h> +static const double grid[4][2] = {{-3 / 3., -1 / 3.}, + {+1 / 3., -3 / 3.}, + {-1 / 3., +3 / 3.}, + {+3 / 3., +1 / 3.}}; - static const double grid[4][2] = { - {-3/3.,-1/3.},{+1/3.,-3/3.}, - {-1/3.,+3/3.},{+3/3.,+1/3.} - }; - - int main() { - for (int i = 0; i < 4; i++) - printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); - printf("\n"); - return 0; - } -
\ No newline at end of file +int main() { + for (int i = 0; i < 4; i++) + printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); + printf("\n"); + return 0; +} diff --git a/tests/core/test_array2b.in b/tests/core/test_array2b.in index b94821d8..97ace8db 100644 --- a/tests/core/test_array2b.in +++ b/tests/core/test_array2b.in @@ -1,16 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +static const struct { + unsigned char left; + unsigned char right; +} prioritah[] = {{6, 6}, {6, 6}, {7, 95}, {7, 7}}; - static const struct { - unsigned char left; - unsigned char right; - } prioritah[] = { - {6, 6}, {6, 6}, {7, 95}, {7, 7} - }; - - int main() { - printf("*%d,%d\n", prioritah[1].left, prioritah[1].right); - printf("%d,%d*\n", prioritah[2].left, prioritah[2].right); - return 0; - } -
\ No newline at end of file +int main() { + printf("*%d,%d\n", prioritah[1].left, prioritah[1].right); + printf("%d,%d*\n", prioritah[2].left, prioritah[2].right); + return 0; +} diff --git a/tests/core/test_assert.in b/tests/core/test_assert.in index 7547468e..3a1898fa 100644 --- a/tests/core/test_assert.in +++ b/tests/core/test_assert.in @@ -1,9 +1,7 @@ - - #include <stdio.h> - #include <assert.h> - int main() { - assert(1 == true); // pass - assert(1 == false); // fail - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <assert.h> +int main() { + assert(1 == true); // pass + assert(1 == false); // fail + return 0; +} diff --git a/tests/core/test_atexit.in b/tests/core/test_atexit.in index 56489a6c..b40c01c0 100644 --- a/tests/core/test_atexit.in +++ b/tests/core/test_atexit.in @@ -1,17 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +static void cleanA() { printf("A"); } +static void cleanB() { printf("B"); } - static void cleanA() { - printf("A"); - } - static void cleanB() { - printf("B"); - } - - int main() { - atexit(cleanA); - atexit(cleanB); - return 0; - } -
\ No newline at end of file +int main() { + atexit(cleanA); + atexit(cleanB); + return 0; +} diff --git a/tests/core/test_atoX.in b/tests/core/test_atoX.in index 8325acfa..327871b8 100644 --- a/tests/core/test_atoX.in +++ b/tests/core/test_atoX.in @@ -1,42 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main () { - printf("%d*", atoi("")); - printf("%d*", atoi("a")); - printf("%d*", atoi(" b")); - printf("%d*", atoi(" c ")); - printf("%d*", atoi("6")); - printf("%d*", atoi(" 5")); - printf("%d*", atoi("4 ")); - printf("%d*", atoi("3 6")); - printf("%d*", atoi(" 3 7")); - printf("%d*", atoi("9 d")); - printf("%d\n", atoi(" 8 e")); - printf("%d*", atol("")); - printf("%d*", atol("a")); - printf("%d*", atol(" b")); - printf("%d*", atol(" c ")); - printf("%d*", atol("6")); - printf("%d*", atol(" 5")); - printf("%d*", atol("4 ")); - printf("%d*", atol("3 6")); - printf("%d*", atol(" 3 7")); - printf("%d*", atol("9 d")); - printf("%d\n", atol(" 8 e")); - printf("%lld*", atoll("6294967296")); - printf("%lld*", atoll("")); - printf("%lld*", atoll("a")); - printf("%lld*", atoll(" b")); - printf("%lld*", atoll(" c ")); - printf("%lld*", atoll("6")); - printf("%lld*", atoll(" 5")); - printf("%lld*", atoll("4 ")); - printf("%lld*", atoll("3 6")); - printf("%lld*", atoll(" 3 7")); - printf("%lld*", atoll("9 d")); - printf("%lld\n", atoll(" 8 e")); - return 0; - } -
\ No newline at end of file +int main() { + printf("%d*", atoi("")); + printf("%d*", atoi("a")); + printf("%d*", atoi(" b")); + printf("%d*", atoi(" c ")); + printf("%d*", atoi("6")); + printf("%d*", atoi(" 5")); + printf("%d*", atoi("4 ")); + printf("%d*", atoi("3 6")); + printf("%d*", atoi(" 3 7")); + printf("%d*", atoi("9 d")); + printf("%d\n", atoi(" 8 e")); + printf("%d*", atol("")); + printf("%d*", atol("a")); + printf("%d*", atol(" b")); + printf("%d*", atol(" c ")); + printf("%d*", atol("6")); + printf("%d*", atol(" 5")); + printf("%d*", atol("4 ")); + printf("%d*", atol("3 6")); + printf("%d*", atol(" 3 7")); + printf("%d*", atol("9 d")); + printf("%d\n", atol(" 8 e")); + printf("%lld*", atoll("6294967296")); + printf("%lld*", atoll("")); + printf("%lld*", atoll("a")); + printf("%lld*", atoll(" b")); + printf("%lld*", atoll(" c ")); + printf("%lld*", atoll("6")); + printf("%lld*", atoll(" 5")); + printf("%lld*", atoll("4 ")); + printf("%lld*", atoll("3 6")); + printf("%lld*", atoll(" 3 7")); + printf("%lld*", atoll("9 d")); + printf("%lld\n", atoll(" 8 e")); + return 0; +} diff --git a/tests/core/test_atomic.in b/tests/core/test_atomic.in index d0950551..2390941f 100644 --- a/tests/core/test_atomic.in +++ b/tests/core/test_atomic.in @@ -1,20 +1,18 @@ - - #include <stdio.h> - int main() { - int x = 10; - int y = __sync_add_and_fetch(&x, 5); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_fetch_and_add(&x, 5); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_lock_test_and_set(&x, 6); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_bool_compare_and_swap(&x, 9, 7); - printf("*%d,%d*\n", x, y); - y = __sync_bool_compare_and_swap(&x, 10, 7); - printf("*%d,%d*\n", x, y); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 10; + int y = __sync_add_and_fetch(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_fetch_and_add(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_lock_test_and_set(&x, 6); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_bool_compare_and_swap(&x, 9, 7); + printf("*%d,%d*\n", x, y); + y = __sync_bool_compare_and_swap(&x, 10, 7); + printf("*%d,%d*\n", x, y); + return 0; +} diff --git a/tests/core/test_bigarray.in b/tests/core/test_bigarray.in index 0255c207..292a44e5 100644 --- a/tests/core/test_bigarray.in +++ b/tests/core/test_bigarray.in @@ -1,19 +1,22 @@ - // avoid "array initializer too large" errors - #include <stdio.h> - #include <assert.h> +#include <stdio.h> +#include <assert.h> - #define SIZE (1024*100) - struct Struct { - char x; - int y; - }; - Struct buffy[SIZE]; +#define SIZE (1024 * 100) +struct Struct { + char x; + int y; +}; +Struct buffy[SIZE]; - int main() { - for (int i = 0; i < SIZE; i++) { assert(buffy[i].x == 0 && buffy[i].y == 0); } // we were zeroinitialized - for (int i = 0; i < SIZE; i++) { buffy[i].x = i*i; buffy[i].y = i*i*i; } // we can save data - printf("*%d*\n", buffy[SIZE/3].x); - return 0; - } - +int main() { + for (int i = 0; i < SIZE; i++) { + assert(buffy[i].x == 0 && buffy[i].y == 0); + } // we were zeroinitialized + for (int i = 0; i < SIZE; i++) { + buffy[i].x = i * i; + buffy[i].y = i * i * i; + } // we can save data + printf("*%d*\n", buffy[SIZE / 3].x); + return 0; +} diff --git a/tests/core/test_bitfields.in b/tests/core/test_bitfields.in index 08831f23..cbc7ccf2 100644 --- a/tests/core/test_bitfields.in +++ b/tests/core/test_bitfields.in @@ -1,23 +1,20 @@ - - #include <stdio.h> - struct bitty { - unsigned x : 1; - unsigned y : 1; - unsigned z : 1; - }; - int main() - { - bitty b; - printf("*"); - for (int i = 0; i <= 1; i++) - for (int j = 0; j <= 1; j++) - for (int k = 0; k <= 1; k++) { - b.x = i; - b.y = j; - b.z = k; - printf("%d,%d,%d,", b.x, b.y, b.z); - } - printf("*\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct bitty { + unsigned x : 1; + unsigned y : 1; + unsigned z : 1; +}; +int main() { + bitty b; + printf("*"); + for (int i = 0; i <= 1; i++) + for (int j = 0; j <= 1; j++) + for (int k = 0; k <= 1; k++) { + b.x = i; + b.y = j; + b.z = k; + printf("%d,%d,%d,", b.x, b.y, b.z); + } + printf("*\n"); + return 0; +} diff --git a/tests/core/test_bsearch.in b/tests/core/test_bsearch.in index 285210bd..3b5fb6bc 100644 --- a/tests/core/test_bsearch.in +++ b/tests/core/test_bsearch.in @@ -1,47 +1,45 @@ - - #include <stdlib.h> - #include <stdio.h> - - int cmp(const void* key, const void* member) { - return *(int *)key - *(int *)member; - } - - void printResult(int* needle, int* haystack, unsigned int len) { - void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp); - - if (result == NULL) { - printf("null\n"); - } else { - printf("%d\n", *(unsigned int *)result); - } - } - - int main() { - int a[] = { -2, -1, 0, 6, 7, 9 }; - int b[] = { 0, 1 }; - - /* Find all keys that exist. */ - for(int i = 0; i < 6; i++) { - int val = a[i]; - - printResult(&val, a, 6); - } - - /* Keys that are covered by the range of the array but aren't in - * the array cannot be found. - */ - int v1 = 3; - int v2 = 8; - printResult(&v1, a, 6); - printResult(&v2, a, 6); - - /* Keys outside the range of the array cannot be found. */ - int v3 = -1; - int v4 = 2; - - printResult(&v3, b, 2); - printResult(&v4, b, 2); - - return 0; - } -
\ No newline at end of file +#include <stdlib.h> +#include <stdio.h> + +int cmp(const void* key, const void* member) { + return *(int*)key - *(int*)member; +} + +void printResult(int* needle, int* haystack, unsigned int len) { + void* result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp); + + if (result == NULL) { + printf("null\n"); + } else { + printf("%d\n", *(unsigned int*)result); + } +} + +int main() { + int a[] = {-2, -1, 0, 6, 7, 9}; + int b[] = {0, 1}; + + /* Find all keys that exist. */ + for (int i = 0; i < 6; i++) { + int val = a[i]; + + printResult(&val, a, 6); + } + + /* Keys that are covered by the range of the array but aren't in + * the array cannot be found. + */ + int v1 = 3; + int v2 = 8; + printResult(&v1, a, 6); + printResult(&v2, a, 6); + + /* Keys outside the range of the array cannot be found. */ + int v3 = -1; + int v4 = 2; + + printResult(&v3, b, 2); + printResult(&v4, b, 2); + + return 0; +} diff --git a/tests/core/test_bswap64.in b/tests/core/test_bswap64.in index addf6086..a608ad22 100644 --- a/tests/core/test_bswap64.in +++ b/tests/core/test_bswap64.in @@ -1,56 +1,48 @@ - - #include <stdio.h> - #include <stdlib.h> - - #include <iostream> - #include <string> - #include <sstream> - - typedef unsigned long long quint64; - - using namespace std; - - inline quint64 qbswap(quint64 source) - { - return 0 - | ((source & quint64(0x00000000000000ffLL)) << 56) - | ((source & quint64(0x000000000000ff00LL)) << 40) - | ((source & quint64(0x0000000000ff0000LL)) << 24) - | ((source & quint64(0x00000000ff000000LL)) << 8) - | ((source & quint64(0x000000ff00000000LL)) >> 8) - | ((source & quint64(0x0000ff0000000000LL)) >> 24) - | ((source & quint64(0x00ff000000000000LL)) >> 40) - | ((source & quint64(0xff00000000000000LL)) >> 56); - } - - int main() - { - quint64 v = strtoull("4433ffeeddccbb00", NULL, 16); - printf("%lld\n", v); - - const string string64bitInt = "4433ffeeddccbb00"; - stringstream s(string64bitInt); - quint64 int64bitInt = 0; - printf("1\n"); - s >> hex >> int64bitInt; - printf("2\n"); - - stringstream out; - out << hex << qbswap(int64bitInt); - - cout << out.str() << endl; - cout << hex << int64bitInt << endl; - cout << string64bitInt << endl; - - if (out.str() != "bbccddeeff3344") - { - cout << "Failed!" << endl; - } - else - { - cout << "Succeeded!" << endl; - } - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> + +#include <iostream> +#include <string> +#include <sstream> + +typedef unsigned long long quint64; + +using namespace std; + +inline quint64 qbswap(quint64 source) { + return 0 | ((source & quint64(0x00000000000000ffLL)) << 56) | + ((source & quint64(0x000000000000ff00LL)) << 40) | + ((source & quint64(0x0000000000ff0000LL)) << 24) | + ((source & quint64(0x00000000ff000000LL)) << 8) | + ((source & quint64(0x000000ff00000000LL)) >> 8) | + ((source & quint64(0x0000ff0000000000LL)) >> 24) | + ((source & quint64(0x00ff000000000000LL)) >> 40) | + ((source & quint64(0xff00000000000000LL)) >> 56); +} + +int main() { + quint64 v = strtoull("4433ffeeddccbb00", NULL, 16); + printf("%lld\n", v); + + const string string64bitInt = "4433ffeeddccbb00"; + stringstream s(string64bitInt); + quint64 int64bitInt = 0; + printf("1\n"); + s >> hex >> int64bitInt; + printf("2\n"); + + stringstream out; + out << hex << qbswap(int64bitInt); + + cout << out.str() << endl; + cout << hex << int64bitInt << endl; + cout << string64bitInt << endl; + + if (out.str() != "bbccddeeff3344") { + cout << "Failed!" << endl; + } else { + cout << "Succeeded!" << endl; + } + + return 0; +} diff --git a/tests/core/test_ccall.in b/tests/core/test_ccall.in index 6374ebb3..0aefdc9d 100644 --- a/tests/core/test_ccall.in +++ b/tests/core/test_ccall.in @@ -1,19 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +extern "C" { +int get_int() { return 5; } +float get_float() { return 3.14; } +char *get_string() { return "hello world"; } +void print_int(int x) { printf("%d\n", x); } +void print_float(float x) { printf("%.2f\n", x); } +void print_string(char *x) { printf("%s\n", x); } +int multi(int x, float y, int z, char *str) { + if (x) puts(str); + return (x + y) * z; +} +int *pointer(int *in) { + printf("%d\n", *in); + static int ret = 21; + return &ret; +} +} - extern "C" { - int get_int() { return 5; } - float get_float() { return 3.14; } - char * get_string() { return "hello world"; } - void print_int(int x) { printf("%d\n", x); } - void print_float(float x) { printf("%.2f\n", x); } - void print_string(char *x) { printf("%s\n", x); } - int multi(int x, float y, int z, char *str) { if (x) puts(str); return (x+y)*z; } - int * pointer(int *in) { printf("%d\n", *in); static int ret = 21; return &ret; } - } - - int main(int argc, char **argv) { - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { return 0; } diff --git a/tests/core/test_class.in b/tests/core/test_class.in index fc61869e..9450b4a1 100644 --- a/tests/core/test_class.in +++ b/tests/core/test_class.in @@ -1,26 +1,28 @@ +#include <stdio.h> +struct Random { + enum { + IM = 139968, + IA = 3877, + IC = 29573 + }; + Random() : last(42) {} + float get(float max = 1.0f) { + last = (last * IA + IC) % IM; + return max * last / IM; + } - #include <stdio.h> - struct Random { - enum { IM = 139968, IA = 3877, IC = 29573 }; - Random() : last(42) {} - float get( float max = 1.0f ) { - last = ( last * IA + IC ) % IM; - return max * last / IM; - } - protected: - unsigned int last; - } rng1; - int main() - { - Random rng2; - int count = 0; - for (int i = 0; i < 100; i++) { - float x1 = rng1.get(); - float x2 = rng2.get(); - printf("%f, %f\n", x1, x2); - if (x1 != x2) count += 1; - } - printf("*%d*\n", count); - return 0; - } -
\ No newline at end of file + protected: + unsigned int last; +} rng1; +int main() { + Random rng2; + int count = 0; + for (int i = 0; i < 100; i++) { + float x1 = rng1.get(); + float x2 = rng2.get(); + printf("%f, %f\n", x1, x2); + if (x1 != x2) count += 1; + } + printf("*%d*\n", count); + return 0; +} diff --git a/tests/core/test_constglobalstructs.in b/tests/core/test_constglobalstructs.in index f2f23c5d..182fae2f 100644 --- a/tests/core/test_constglobalstructs.in +++ b/tests/core/test_constglobalstructs.in @@ -1,30 +1,21 @@ +#include <stdio.h> +struct IUB { + int c; + double p; + unsigned int pi; +}; - #include <stdio.h> - struct IUB { - int c; - double p; - unsigned int pi; - }; +IUB iub[] = {{'a', 0.27, 5}, {'c', 0.15, 4}, {'g', 0.12, 3}, {'t', 0.27, 2}, }; - IUB iub[] = { - { 'a', 0.27, 5 }, - { 'c', 0.15, 4 }, - { 'g', 0.12, 3 }, - { 't', 0.27, 2 }, - }; +const unsigned char faceedgesidx[6][4] = {{4, 5, 8, 10}, + {6, 7, 9, 11}, + {0, 2, 8, 9}, + {1, 3, 10, 11}, + {0, 1, 4, 6}, + {2, 3, 5, 7}, }; - const unsigned char faceedgesidx[6][4] = - { - { 4, 5, 8, 10 }, - { 6, 7, 9, 11 }, - { 0, 2, 8, 9 }, - { 1, 3, 10,11 }, - { 0, 1, 4, 6 }, - { 2, 3, 5, 7 }, - }; - - int main( int argc, const char *argv[] ) { - printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p*100), iub[2].pi, faceedgesidx[3][2]); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p * 100), iub[2].pi, + faceedgesidx[3][2]); + return 0; +} diff --git a/tests/core/test_conststructs.in b/tests/core/test_conststructs.in index e95fd6be..6d664bea 100644 --- a/tests/core/test_conststructs.in +++ b/tests/core/test_conststructs.in @@ -1,21 +1,18 @@ +#include <stdio.h> +struct IUB { + int c; + double p; + unsigned int pi; +}; - #include <stdio.h> - struct IUB { - int c; - double p; - unsigned int pi; - }; - - int main( int argc, const char *argv[] ) { - int before = 70; - IUB iub[] = { - { 'a', 0.3029549426680, 5 }, - { 'c', 0.15, 4 }, - { 'g', 0.12, 3 }, - { 't', 0.27, 2 }, - }; - int after = 90; - printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p*100), iub[2].pi, int(iub[0].p*10000), after); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + int before = 70; + IUB iub[] = {{'a', 0.3029549426680, 5}, + {'c', 0.15, 4}, + {'g', 0.12, 3}, + {'t', 0.27, 2}, }; + int after = 90; + printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p * 100), + iub[2].pi, int(iub[0].p * 10000), after); + return 0; +} diff --git a/tests/core/test_copyop.in b/tests/core/test_copyop.in index 4bf7da12..847a516c 100644 --- a/tests/core/test_copyop.in +++ b/tests/core/test_copyop.in @@ -1,36 +1,34 @@ +#include <stdio.h> +#include <math.h> +#include <string.h> - #include <stdio.h> - #include <math.h> - #include <string.h> +struct vec { + double x, y, z; + vec() : x(0), y(0), z(0) {}; + vec(const double a, const double b, const double c) : x(a), y(b), z(c) {}; +}; - struct vec { - double x,y,z; - vec() : x(0), y(0), z(0) { }; - vec(const double a, const double b, const double c) : x(a), y(b), z(c) { }; - }; +struct basis { + vec a, b, c; + basis(const vec& v) { + a = v; // should not touch b! + printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z); + } +}; - struct basis { - vec a, b, c; - basis(const vec& v) { - a=v; // should not touch b! - printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z); - } - }; +int main() { + basis B(vec(1, 0, 0)); - int main() { - basis B(vec(1,0,0)); - - // Part 2: similar problem with memset and memmove - int x = 1, y = 77, z = 2; - memset((void*)&x, 0, sizeof(int)); - memset((void*)&z, 0, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - memcpy((void*)&x, (void*)&z, sizeof(int)); - memcpy((void*)&z, (void*)&x, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - memmove((void*)&x, (void*)&z, sizeof(int)); - memmove((void*)&z, (void*)&x, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - return 0; - } -
\ No newline at end of file + // Part 2: similar problem with memset and memmove + int x = 1, y = 77, z = 2; + memset((void*)&x, 0, sizeof(int)); + memset((void*)&z, 0, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memcpy((void*)&x, (void*)&z, sizeof(int)); + memcpy((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memmove((void*)&x, (void*)&z, sizeof(int)); + memmove((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + return 0; +} diff --git a/tests/core/test_corruption_2.in b/tests/core/test_corruption_2.in index 87aef9da..4db3b7c4 100644 --- a/tests/core/test_corruption_2.in +++ b/tests/core/test_corruption_2.in @@ -1,26 +1,21 @@ +#include <iostream> +#include <fstream> +#include <stdlib.h> +#include <stdio.h> - #include <iostream> - #include <fstream> - #include <stdlib.h> - #include <stdio.h> +void bye() { printf("all ok\n"); } - void bye() { - printf("all ok\n"); - } +int main() { + atexit(bye); - int main() { - atexit(bye); + std::string testPath = "/Script/WA-KA.txt"; + std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary); - std::string testPath = "/Script/WA-KA.txt"; - std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary); + if (str.is_open()) { + std::cout << "open!" << std::endl; + } else { + std::cout << "missing!" << std::endl; + } - if (str.is_open()) - { - std::cout << "open!" << std::endl; - } else { - std::cout << "missing!" << std::endl; - } - - return 1; - } -
\ No newline at end of file + return 1; +} diff --git a/tests/core/test_corruption_3.in b/tests/core/test_corruption_3.in index b951ac6b..08e7d345 100644 --- a/tests/core/test_corruption_3.in +++ b/tests/core/test_corruption_3.in @@ -1,22 +1,19 @@ +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> - #include <stdlib.h> - #include <stdio.h> - #include <assert.h> +void bye() { printf("all ok\n"); } - void bye() { - printf("all ok\n"); - } +int main(int argc, char **argv) { + atexit(bye); - int main(int argc, char **argv) { - atexit(bye); - - char *buffer = (char*)malloc(100); - for (int i = 0; i < 100; i++) buffer[i] = (i*i)%256; - buffer = (char*)realloc(buffer, argc + 50); - for (int i = 0; i < argc + 50; i++) { - //printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], (char)((i*i)%256)); - assert(buffer[i] == (char)((i*i)%256)); - } - return 1; - } -
\ No newline at end of file + char *buffer = (char *)malloc(100); + for (int i = 0; i < 100; i++) buffer[i] = (i * i) % 256; + buffer = (char *)realloc(buffer, argc + 50); + for (int i = 0; i < argc + 50; i++) { + // printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], + // (char)((i*i)%256)); + assert(buffer[i] == (char)((i * i) % 256)); + } + return 1; +} diff --git a/tests/core/test_cxx03_do_run.in b/tests/core/test_cxx03_do_run.in index ec7d1189..2ed0d2cf 100644 --- a/tests/core/test_cxx03_do_run.in +++ b/tests/core/test_cxx03_do_run.in @@ -1,12 +1,10 @@ +#include <stdio.h> - #include <stdio.h> +#if __cplusplus != 199711L +#error By default, if no -std is specified, emscripten should be compiling with -std=c++03! +#endif - #if __cplusplus != 199711L - #error By default, if no -std is specified, emscripten should be compiling with -std=c++03! - #endif - - int main( int argc, const char *argv[] ) { - printf("Hello world!\n"); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + printf("Hello world!\n"); + return 0; +} diff --git a/tests/core/test_demangle_stacks.in b/tests/core/test_demangle_stacks.in index 8db34832..e19d1a70 100644 --- a/tests/core/test_demangle_stacks.in +++ b/tests/core/test_demangle_stacks.in @@ -1,21 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> - #include<stdio.h> - #include<stdlib.h> +namespace NameSpace { +class Class { + public: + int Aborter(double x, char y, int *z) { + int addr = x + y + (int)z; + void *p = (void *)addr; + for (int i = 0; i < 100; i++) + free(p); // will abort, should show proper stack trace + } +}; +} - namespace NameSpace { - class Class { - public: - int Aborter(double x, char y, int *z) { - int addr = x+y+(int)z; - void *p = (void*)addr; - for (int i = 0; i < 100; i++) free(p); // will abort, should show proper stack trace - } - }; - } - - int main(int argc, char **argv) { - NameSpace::Class c; - c.Aborter(1.234, 'a', NULL); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + NameSpace::Class c; + c.Aborter(1.234, 'a', NULL); + return 0; +} diff --git a/tests/core/test_direct_string_constant_usage.in b/tests/core/test_direct_string_constant_usage.in index e43232f0..cab335bd 100644 --- a/tests/core/test_direct_string_constant_usage.in +++ b/tests/core/test_direct_string_constant_usage.in @@ -1,13 +1,9 @@ - - #include <iostream> - template<int i> - void printText( const char (&text)[ i ] ) - { - std::cout << text; - } - int main() - { - printText( "some string constant" ); - return 0; - } -
\ No newline at end of file +#include <iostream> +template <int i> +void printText(const char (&text)[i]) { + std::cout << text; +} +int main() { + printText("some string constant"); + return 0; +} diff --git a/tests/core/test_dlfcn_self.in b/tests/core/test_dlfcn_self.in index 687c4d6f..7094b97d 100644 --- a/tests/core/test_dlfcn_self.in +++ b/tests/core/test_dlfcn_self.in @@ -1,4 +1,3 @@ - #include <stdio.h> #include <dlfcn.h> #include <emscripten.h> @@ -6,19 +5,19 @@ int EMSCRIPTEN_KEEPALIVE global = 123; extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) { -printf("%d\n", x); + printf("%d\n", x); } extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() { -void* self = dlopen(NULL, RTLD_LAZY); -int* global_ptr = (int*)dlsym(self, "global"); -void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); -foo_ptr(*global_ptr); -dlclose(self); + void* self = dlopen(NULL, RTLD_LAZY); + int* global_ptr = (int*)dlsym(self, "global"); + void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); + foo_ptr(*global_ptr); + dlclose(self); } int main() { -repeatable(); -repeatable(); -return 0; -}
\ No newline at end of file + repeatable(); + repeatable(); + return 0; +} diff --git a/tests/core/test_dlmalloc_partial_2.in b/tests/core/test_dlmalloc_partial_2.in index f68e9cdf..1e16657e 100644 --- a/tests/core/test_dlmalloc_partial_2.in +++ b/tests/core/test_dlmalloc_partial_2.in @@ -1,14 +1,10 @@ - - #include <stdio.h> - #include <stdlib.h> - void *malloc(size_t size) - { - return (void*)123; - } - int main() { - void *x = malloc(10); - printf("got %p\n", x); - free(x); - printf("freed the faker\n"); - return 1; - } +#include <stdio.h> +#include <stdlib.h> +void *malloc(size_t size) { return (void *)123; } +int main() { + void *x = malloc(10); + printf("got %p\n", x); + free(x); + printf("freed the faker\n"); + return 1; +} diff --git a/tests/core/test_double_i64_conversion.in b/tests/core/test_double_i64_conversion.in index 404c6796..4033e211 100644 --- a/tests/core/test_double_i64_conversion.in +++ b/tests/core/test_double_i64_conversion.in @@ -1,69 +1,69 @@ +#include <cassert> +#include <inttypes.h> +#include <stdio.h> - #include <cassert> - #include <inttypes.h> - #include <stdio.h> +__attribute((noinline)) bool eq(double d, int64_t i) { + int64_t i2 = (int64_t)d; + if (i != i2) { + printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, + i2, i); + } + return i == i2; +} - __attribute((noinline)) bool eq(double d, int64_t i) { - int64_t i2 = (int64_t)d; - if (i != i2) { - printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, i2, i); - } - return i == i2; - } +int main() { + assert(eq(0.0, 0)); + assert(eq(-0.0, 0)); + assert(eq(0.1, 0)); + assert(eq(-0.1, 0)); + assert(eq(0.6, 0)); + assert(eq(-0.6, 0)); + assert(eq(1.0, 1)); + assert(eq(-1.0, -1)); + assert(eq(1.1, 1)); + assert(eq(-1.1, -1)); + assert(eq(1.6, 1)); + assert(eq(-1.6, -1)); + assert(eq(4294967295.0, 4294967295LL)); + assert(eq(4294967295.5, 4294967295LL)); + assert(eq(4294967296.0, 4294967296LL)); + assert(eq(4294967296.5, 4294967296LL)); + assert(eq(14294967295.0, 14294967295LL)); + assert(eq(14294967295.5, 14294967295LL)); + assert(eq(14294967296.0, 14294967296LL)); + assert(eq(14294967296.5, 14294967296LL)); + assert(eq(-4294967295.0, -4294967295LL)); + assert(eq(-4294967295.5, -4294967295LL)); + assert(eq(-4294967296.0, -4294967296LL)); + assert(eq(-4294967296.5, -4294967296LL)); + assert(eq(-14294967295.0, -14294967295LL)); + assert(eq(-14294967295.5, -14294967295LL)); + assert(eq(-14294967296.0, -14294967296LL)); + assert(eq(-14294967296.5, -14294967296LL)); - int main() { - assert(eq(0.0, 0)); - assert(eq(-0.0, 0)); - assert(eq(0.1, 0)); - assert(eq(-0.1, 0)); - assert(eq(0.6, 0)); - assert(eq(-0.6, 0)); - assert(eq(1.0, 1)); - assert(eq(-1.0, -1)); - assert(eq(1.1, 1)); - assert(eq(-1.1, -1)); - assert(eq(1.6, 1)); - assert(eq(-1.6, -1)); - assert(eq(4294967295.0, 4294967295LL)); - assert(eq(4294967295.5, 4294967295LL)); - assert(eq(4294967296.0, 4294967296LL)); - assert(eq(4294967296.5, 4294967296LL)); - assert(eq(14294967295.0, 14294967295LL)); - assert(eq(14294967295.5, 14294967295LL)); - assert(eq(14294967296.0, 14294967296LL)); - assert(eq(14294967296.5, 14294967296LL)); - assert(eq(-4294967295.0, -4294967295LL)); - assert(eq(-4294967295.5, -4294967295LL)); - assert(eq(-4294967296.0, -4294967296LL)); - assert(eq(-4294967296.5, -4294967296LL)); - assert(eq(-14294967295.0, -14294967295LL)); - assert(eq(-14294967295.5, -14294967295LL)); - assert(eq(-14294967296.0, -14294967296LL)); - assert(eq(-14294967296.5, -14294967296LL)); + assert(eq(4294967295.3, 4294967295LL)); + assert(eq(4294967296.3, 4294967296LL)); + assert(eq(14294967295.3, 14294967295LL)); + assert(eq(14294967296.3, 14294967296LL)); + assert(eq(-4294967295.3, -4294967295LL)); + assert(eq(-4294967296.3, -4294967296LL)); + assert(eq(-14294967295.3, -14294967295LL)); + assert(eq(-14294967296.3, -14294967296LL)); - assert(eq(4294967295.3, 4294967295LL)); - assert(eq(4294967296.3, 4294967296LL)); - assert(eq(14294967295.3, 14294967295LL)); - assert(eq(14294967296.3, 14294967296LL)); - assert(eq(-4294967295.3, -4294967295LL)); - assert(eq(-4294967296.3, -4294967296LL)); - assert(eq(-14294967295.3, -14294967295LL)); - assert(eq(-14294967296.3, -14294967296LL)); + assert(eq(4294967295.8, 4294967295LL)); + assert(eq(4294967296.8, 4294967296LL)); + assert(eq(14294967295.8, 14294967295LL)); + assert(eq(14294967296.8, 14294967296LL)); + assert(eq(-4294967295.8, -4294967295LL)); + assert(eq(-4294967296.8, -4294967296LL)); + assert(eq(-14294967295.8, -14294967295LL)); + assert(eq(-14294967296.8, -14294967296LL)); - assert(eq(4294967295.8, 4294967295LL)); - assert(eq(4294967296.8, 4294967296LL)); - assert(eq(14294967295.8, 14294967295LL)); - assert(eq(14294967296.8, 14294967296LL)); - assert(eq(-4294967295.8, -4294967295LL)); - assert(eq(-4294967296.8, -4294967296LL)); - assert(eq(-14294967295.8, -14294967295LL)); - assert(eq(-14294967296.8, -14294967296LL)); + // The following number is the largest double such that all integers smaller + // than this can exactly be represented in a double. + assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */)); + assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */)); - // The following number is the largest double such that all integers smaller than this can exactly be represented in a double. - assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */)); - assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */)); - - printf("OK!\n"); - return 0; - } -
\ No newline at end of file + printf("OK!\n"); + return 0; +} diff --git a/tests/core/test_dynamic_cast.in b/tests/core/test_dynamic_cast.in index ebe9263b..1752573c 100644 --- a/tests/core/test_dynamic_cast.in +++ b/tests/core/test_dynamic_cast.in @@ -1,17 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +struct Support { + virtual void f() { printf("f()\n"); } +}; - struct Support { - virtual void f() { - printf("f()\n"); - } - }; +struct Derived : Support {}; - struct Derived : Support { - }; - - int main() { - Support * p = new Derived; - dynamic_cast<Derived*>(p)->f(); - } -
\ No newline at end of file +int main() { + Support* p = new Derived; + dynamic_cast<Derived*>(p)->f(); +} diff --git a/tests/core/test_dynamic_cast_2.in b/tests/core/test_dynamic_cast_2.in index 6da4cade..634ff5c2 100644 --- a/tests/core/test_dynamic_cast_2.in +++ b/tests/core/test_dynamic_cast_2.in @@ -1,12 +1,10 @@ +#include <stdio.h> +#include <typeinfo> - #include <stdio.h> - #include <typeinfo> +class Class {}; - class Class {}; - - int main() { - const Class* dp = dynamic_cast<const Class*>(&typeid(Class)); - // should return dp == NULL, - printf("pointer: %p\n", dp); - } -
\ No newline at end of file +int main() { + const Class* dp = dynamic_cast<const Class*>(&typeid(Class)); + // should return dp == NULL, + printf("pointer: %p\n", dp); +} diff --git a/tests/core/test_dynamic_cast_b.in b/tests/core/test_dynamic_cast_b.in index f5931fef..77981035 100644 --- a/tests/core/test_dynamic_cast_b.in +++ b/tests/core/test_dynamic_cast_b.in @@ -1,28 +1,31 @@ +#include <stdio.h> - #include <stdio.h> +class CBase { + virtual void dummy() {} +}; +class CDerived : public CBase { + int a; +}; +class CDerivedest : public CDerived { + float b; +}; - class CBase { virtual void dummy() {} }; - class CDerived : public CBase { int a; }; - class CDerivedest : public CDerived { float b; }; +int main() { + CBase *pa = new CBase; + CBase *pb = new CDerived; + CBase *pc = new CDerivedest; - int main () - { - CBase *pa = new CBase; - CBase *pb = new CDerived; - CBase *pc = new CDerivedest; + printf("a1: %d\n", dynamic_cast<CDerivedest *>(pa) != NULL); + printf("a2: %d\n", dynamic_cast<CDerived *>(pa) != NULL); + printf("a3: %d\n", dynamic_cast<CBase *>(pa) != NULL); - printf("a1: %d\n", dynamic_cast<CDerivedest*>(pa) != NULL); - printf("a2: %d\n", dynamic_cast<CDerived*>(pa) != NULL); - printf("a3: %d\n", dynamic_cast<CBase*>(pa) != NULL); + printf("b1: %d\n", dynamic_cast<CDerivedest *>(pb) != NULL); + printf("b2: %d\n", dynamic_cast<CDerived *>(pb) != NULL); + printf("b3: %d\n", dynamic_cast<CBase *>(pb) != NULL); - printf("b1: %d\n", dynamic_cast<CDerivedest*>(pb) != NULL); - printf("b2: %d\n", dynamic_cast<CDerived*>(pb) != NULL); - printf("b3: %d\n", dynamic_cast<CBase*>(pb) != NULL); + printf("c1: %d\n", dynamic_cast<CDerivedest *>(pc) != NULL); + printf("c2: %d\n", dynamic_cast<CDerived *>(pc) != NULL); + printf("c3: %d\n", dynamic_cast<CBase *>(pc) != NULL); - printf("c1: %d\n", dynamic_cast<CDerivedest*>(pc) != NULL); - printf("c2: %d\n", dynamic_cast<CDerived*>(pc) != NULL); - printf("c3: %d\n", dynamic_cast<CBase*>(pc) != NULL); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_emptyclass.in b/tests/core/test_emptyclass.in index 24a550db..370cacf5 100644 --- a/tests/core/test_emptyclass.in +++ b/tests/core/test_emptyclass.in @@ -1,15 +1,11 @@ +#include <stdio.h> - #include <stdio.h> +struct Randomized { + Randomized(int x) { printf("*zzcheezzz*\n"); } +}; - struct Randomized { - Randomized(int x) { - printf("*zzcheezzz*\n"); - } - }; +int main(int argc, const char *argv[]) { + new Randomized(55); - int main( int argc, const char *argv[] ) { - new Randomized(55); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_emscripten_api.in b/tests/core/test_emscripten_api.in index fb25175e..7ece877f 100644 --- a/tests/core/test_emscripten_api.in +++ b/tests/core/test_emscripten_api.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include "emscripten.h" - #include <stdio.h> - #include "emscripten.h" +extern "C" { +void save_me_aimee() { printf("mann\n"); } +} - extern "C" { - void save_me_aimee() { printf("mann\n"); } - } - - int main() { - // EMSCRIPTEN_COMMENT("hello from the source"); - emscripten_run_script("Module.print('hello world' + '!')"); - printf("*%d*\n", emscripten_run_script_int("5*20")); - printf("*%s*\n", emscripten_run_script_string("'five'+'six'")); - emscripten_run_script("Module['_save_me_aimee']()"); - return 0; - } -
\ No newline at end of file +int main() { + // EMSCRIPTEN_COMMENT("hello from the source"); + emscripten_run_script("Module.print('hello world' + '!')"); + printf("*%d*\n", emscripten_run_script_int("5*20")); + printf("*%s*\n", emscripten_run_script_string("'five'+'six'")); + emscripten_run_script("Module['_save_me_aimee']()"); + return 0; +} diff --git a/tests/core/test_erf.in b/tests/core/test_erf.in index 70658ea5..bd14b14f 100644 --- a/tests/core/test_erf.in +++ b/tests/core/test_erf.in @@ -1,15 +1,7 @@ - - #include <math.h> - #include <stdio.h> - int main() - { - printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n", - erf(1.0), - erf(3.0), - erf(-1.0), - erfc(1.0), - erfc(3.0), - erfc(-1.5)); - return 0; - } -
\ No newline at end of file +#include <math.h> +#include <stdio.h> +int main() { + printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n", erf(1.0), erf(3.0), + erf(-1.0), erfc(1.0), erfc(3.0), erfc(-1.5)); + return 0; +} diff --git a/tests/core/test_errar.in b/tests/core/test_errar.in index 7ef2b23d..9fda2099 100644 --- a/tests/core/test_errar.in +++ b/tests/core/test_errar.in @@ -1,21 +1,19 @@ +#include <stdio.h> +#include <errno.h> +#include <string.h> - #include <stdio.h> - #include <errno.h> - #include <string.h> +int main() { + char* err; + char buffer[200]; - int main() { - char* err; - char buffer[200]; + err = strerror(EDOM); + strerror_r(EWOULDBLOCK, buffer, 200); + printf("<%s>\n", err); + printf("<%s>\n", buffer); - err = strerror(EDOM); - strerror_r(EWOULDBLOCK, buffer, 200); - printf("<%s>\n", err); - printf("<%s>\n", buffer); + printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0)); + errno = 123; + printf("<%d>\n", errno); - printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0)); - errno = 123; - printf("<%d>\n", errno); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_exception_2.in b/tests/core/test_exception_2.in index 5a9efce5..2eae3198 100644 --- a/tests/core/test_exception_2.in +++ b/tests/core/test_exception_2.in @@ -1,26 +1,18 @@ +#include <stdexcept> +#include <stdio.h> - #include <stdexcept> - #include <stdio.h> +typedef void (*FuncPtr)(); - typedef void (*FuncPtr)(); +void ThrowException() { throw std::runtime_error("catch me!"); } - void ThrowException() - { - throw std::runtime_error("catch me!"); - } +FuncPtr ptr = ThrowException; - FuncPtr ptr = ThrowException; - - int main() - { - try - { - ptr(); - } - catch(...) - { - printf("Exception caught successfully!\n"); - } - return 0; - } -
\ No newline at end of file +int main() { + try { + ptr(); + } + catch (...) { + printf("Exception caught successfully!\n"); + } + return 0; +} diff --git a/tests/core/test_fakestat.in b/tests/core/test_fakestat.in index 9a09b57c..d1dbed29 100644 --- a/tests/core/test_fakestat.in +++ b/tests/core/test_fakestat.in @@ -1,10 +1,10 @@ - - #include <stdio.h> - struct stat { int x, y; }; - int main() { - stat s; - s.x = 10; - s.y = 22; - printf("*%d,%d*\n", s.x, s.y); - } -
\ No newline at end of file +#include <stdio.h> +struct stat { + int x, y; +}; +int main() { + stat s; + s.x = 10; + s.y = 22; + printf("*%d,%d*\n", s.x, s.y); +} diff --git a/tests/core/test_fast_math.in b/tests/core/test_fast_math.in index 27bd01fd..e3b283aa 100644 --- a/tests/core/test_fast_math.in +++ b/tests/core/test_fast_math.in @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> diff --git a/tests/core/test_fcvt.in b/tests/core/test_fcvt.in index 66b5adef..2e3fdbc6 100644 --- a/tests/core/test_fcvt.in +++ b/tests/core/test_fcvt.in @@ -1,14 +1,12 @@ -/* This example borrowed from MSDN documentation */ - #include <stdlib.h> - #include <stdio.h> +/* This example borrowed from MSDN documentation */#include <stdlib.h> +#include <stdio.h> - int main() { - int decimal, sign; - char *buffer; - double source = 3.1415926535; +int main() { + int decimal, sign; + char *buffer; + double source = 3.1415926535; - buffer = fcvt(source, 7, &decimal, &sign); - printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", - source, buffer, decimal, sign); - } - + buffer = fcvt(source, 7, &decimal, &sign); + printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, + buffer, decimal, sign); +} diff --git a/tests/core/test_flexarray_struct.in b/tests/core/test_flexarray_struct.in index 40ee1ddd..cb83a7e5 100644 --- a/tests/core/test_flexarray_struct.in +++ b/tests/core/test_flexarray_struct.in @@ -1,13 +1,10 @@ - #include <stdint.h> #include <stdlib.h> #include <stdio.h> -typedef struct -{ +typedef struct { uint16_t length; - struct - { + struct { int32_t int32; } value[]; } Tuple; diff --git a/tests/core/test_float32_precise.in b/tests/core/test_float32_precise.in index 231b4289..969f5ed6 100644 --- a/tests/core/test_float32_precise.in +++ b/tests/core/test_float32_precise.in @@ -1,21 +1,19 @@ +#include <stdio.h> - #include <stdio.h> - - int main(int argc, char **argv) { - float x = 1.23456789123456789; - float y = 5.20456089123406709; - while (argc > 10 || argc % 19 == 15) { - // confuse optimizer - x /= y; - y = 2*y - 1; - argc--; - } - x = x - y; - y = 3*y - x/2; - x = x*y; - y += 0.000000000123123123123; - x -= y/7.654; - printf("\n%.20f, %.20f\n", x, y); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + float x = 1.23456789123456789; + float y = 5.20456089123406709; + while (argc > 10 || argc % 19 == 15) { + // confuse optimizer + x /= y; + y = 2 * y - 1; + argc--; + } + x = x - y; + y = 3 * y - x / 2; + x = x * y; + y += 0.000000000123123123123; + x -= y / 7.654; + printf("\n%.20f, %.20f\n", x, y); + return 0; +} diff --git a/tests/core/test_floatvars.in b/tests/core/test_floatvars.in index f63da19c..b6c94c82 100644 --- a/tests/core/test_floatvars.in +++ b/tests/core/test_floatvars.in @@ -1,29 +1,27 @@ +#include <stdio.h> - #include <stdio.h> +// headers test, see issue #1013 +#include <cfloat> +#include <cmath> - // headers test, see issue #1013 - #include<cfloat> - #include<cmath> +int main(int argc, char **argv) { + float x = 1.234, y = 3.5, q = 0.00000001; + y *= 3; + int z = x < y; + printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q); - int main(int argc, char **argv) - { - float x = 1.234, y = 3.5, q = 0.00000001; - y *= 3; - int z = x < y; - printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q); + printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), + fmax(0.5, 3.3), fmax(NAN, 3.3)); - printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), fmax(0.5, 3.3), fmax(NAN, 3.3)); + printf("small: %.10f\n", argc * 0.000001); - printf("small: %.10f\n", argc * 0.000001); + /* + // Rounding behavior + float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; + double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; + for (int i = 0; i < 6; i++) + printf("*int(%.2f)=%d,%d*\n", fs[i], int(fs[i]), int(ds[i])); + */ - /* - // Rounding behavior - float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; - double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; - for (int i = 0; i < 6; i++) - printf("*int(%.2f)=%d,%d*\n", fs[i], int(fs[i]), int(ds[i])); - */ - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_frexp.in b/tests/core/test_frexp.in index d3facca8..fba3231f 100644 --- a/tests/core/test_frexp.in +++ b/tests/core/test_frexp.in @@ -1,32 +1,29 @@ +#include <stdio.h> +#include <math.h> +#include <assert.h> - #include <stdio.h> - #include <math.h> - #include <assert.h> +static const double tol = 1e-16; - static const double tol=1e-16; +void test_value(double value) { + int exponent; + double x = frexp(value, &exponent); + double expected = x * pow(2.0, exponent); - void test_value(double value) - { - int exponent; - double x=frexp(value, &exponent); - double expected=x*pow(2.0, exponent); + printf("%f=%f*2^%d\n", value, x, exponent); - printf("%f=%f*2^%d\n", value, x, exponent); + assert(fabs(expected - value) < tol); + assert(x == 0 || (fabs(x) >= 5e-1 && fabs(x) < 1)); // x has a magnitude in + // the interval [1/2, 1) +} - assert(fabs(expected-value)<tol); - assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1) - } +int main() { + test_value(0); + test_value(100.1); + test_value(-100.1); + test_value(.5); + test_value(-.5); + test_value(1 - 1e-16); + test_value(-(1 - 1e-16)); - int main() - { - test_value(0); - test_value(100.1); - test_value(-100.1); - test_value(.5); - test_value(-.5); - test_value(1-1e-16); - test_value(-(1-1e-16)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_funcptr.in b/tests/core/test_funcptr.in index 8328924a..23813b33 100644 --- a/tests/core/test_funcptr.in +++ b/tests/core/test_funcptr.in @@ -1,35 +1,33 @@ +#include <stdio.h> +int calc1() { return 26; } +int calc2() { return 90; } +typedef int (*fp_t)(); - #include <stdio.h> - int calc1() { return 26; } - int calc2() { return 90; } - typedef int (*fp_t)(); +fp_t globally1 = calc1; +fp_t globally2 = calc2; - fp_t globally1 = calc1; - fp_t globally2 = calc2; +int nothing(const char *str) { return 0; } - int nothing(const char *str) { return 0; } +int main() { + fp_t fp = calc1; + void *vp = (void *)fp; + fp_t fpb = (fp_t)vp; + fp_t fp2 = calc2; + void *vp2 = (void *)fp2; + fp_t fpb2 = (fp_t)vp2; + printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), + globally2()); - int main() - { - fp_t fp = calc1; - void *vp = (void*)fp; - fp_t fpb = (fp_t)vp; - fp_t fp2 = calc2; - void *vp2 = (void*)fp2; - fp_t fpb2 = (fp_t)vp2; - printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2()); + fp_t t = calc1; + printf("*%d,%d", t == calc1, t == calc2); + t = calc2; + printf(",%d,%d*\n", t == calc1, t == calc2); - fp_t t = calc1; - printf("*%d,%d", t == calc1, t == calc2); - t = calc2; - printf(",%d,%d*\n", t == calc1, t == calc2); + int (*other)(const char * str); + other = nothing; + other("*hello!*"); + other = puts; + other("*goodbye!*"); - int (*other)(const char *str); - other = nothing; - other("*hello!*"); - other = puts; - other("*goodbye!*"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_funcptr_namecollide.in b/tests/core/test_funcptr_namecollide.in index 0b27b07c..dc5cfaba 100644 --- a/tests/core/test_funcptr_namecollide.in +++ b/tests/core/test_funcptr_namecollide.in @@ -1,27 +1,24 @@ +#include <stdio.h> - #include <stdio.h> +void do_call(void (*puts)(const char *), const char *str); - void do_call(void (*puts)(const char *), const char *str); +void do_print(const char *str) { + if (!str) do_call(NULL, "delusion"); + if ((int)str == -1) do_print(str + 10); + puts("===="); + puts(str); + puts("===="); +} - void do_print(const char *str) { - if (!str) do_call(NULL, "delusion"); - if ((int)str == -1) do_print(str+10); - puts("===="); - puts(str); - puts("===="); - } +void do_call(void (*puts)(const char *), const char *str) { + if (!str) do_print("confusion"); + if ((int)str == -1) do_call(NULL, str - 10); + (*puts)(str); +} - void do_call(void (*puts)(const char *), const char *str) { - if (!str) do_print("confusion"); - if ((int)str == -1) do_call(NULL, str-10); - (*puts)(str); - } - - int main(int argc, char **argv) - { - for (int i = 0; i < argc; i++) { - do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL); - } - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + for (int i = 0; i < argc; i++) { + do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL); + } + return 0; +} diff --git a/tests/core/test_funcptrfunc.in b/tests/core/test_funcptrfunc.in index 6c146421..c6487b88 100644 --- a/tests/core/test_funcptrfunc.in +++ b/tests/core/test_funcptrfunc.in @@ -1,17 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +typedef void (*funcptr)(int, int); +typedef funcptr (*funcptrfunc)(int); - typedef void (*funcptr)(int, int); - typedef funcptr (*funcptrfunc)(int); +funcptr __attribute__((noinline)) getIt(int x) { return (funcptr)x; } - funcptr __attribute__ ((noinline)) getIt(int x) { - return (funcptr)x; - } - - int main(int argc, char **argv) - { - funcptrfunc fpf = argc < 100 ? getIt : NULL; - printf("*%p*\n", fpf(argc)); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + funcptrfunc fpf = argc < 100 ? getIt : NULL; + printf("*%p*\n", fpf(argc)); + return 0; +} diff --git a/tests/core/test_funcs.in b/tests/core/test_funcs.in index f2e707f9..3619faec 100644 --- a/tests/core/test_funcs.in +++ b/tests/core/test_funcs.in @@ -1,12 +1,6 @@ - - #include <stdio.h> - int funcy(int x) - { - return x*9; - } - int main() - { - printf("*%d,%d*\n", funcy(8), funcy(10)); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int funcy(int x) { return x * 9; } +int main() { + printf("*%d,%d*\n", funcy(8), funcy(10)); + return 0; +} diff --git a/tests/core/test_functionpointer_libfunc_varargs.in b/tests/core/test_functionpointer_libfunc_varargs.in index 6cabe8c5..69faefa2 100644 --- a/tests/core/test_functionpointer_libfunc_varargs.in +++ b/tests/core/test_functionpointer_libfunc_varargs.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - #include <fcntl.h> - typedef int (*fp_t)(int, int, ...); - int main(int argc, char **argv) { - fp_t fp = &fcntl; - if (argc == 1337) fp = (fp_t)&main; - (*fp)(0, 10); - (*fp)(0, 10, 5); - printf("waka\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <fcntl.h> +typedef int (*fp_t)(int, int, ...); +int main(int argc, char **argv) { + fp_t fp = &fcntl; + if (argc == 1337) fp = (fp_t) & main; + (*fp)(0, 10); + (*fp)(0, 10, 5); + printf("waka\n"); + return 0; +} diff --git a/tests/core/test_fwrite_0.in b/tests/core/test_fwrite_0.in index 478524bb..990ab250 100644 --- a/tests/core/test_fwrite_0.in +++ b/tests/core/test_fwrite_0.in @@ -1,21 +1,18 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + FILE *fh; - int main () - { - FILE *fh; + fh = fopen("a.txt", "wb"); + if (!fh) exit(1); + fclose(fh); - fh = fopen("a.txt", "wb"); - if (!fh) exit(1); - fclose(fh); + fh = fopen("a.txt", "rb"); + if (!fh) exit(1); - fh = fopen("a.txt", "rb"); - if (!fh) exit(1); + char data[] = "foobar"; + size_t written = fwrite(data, 1, sizeof(data), fh); - char data[] = "foobar"; - size_t written = fwrite(data, 1, sizeof(data), fh); - - printf("written=%zu\n", written); - } -
\ No newline at end of file + printf("written=%zu\n", written); +} diff --git a/tests/core/test_gc.in b/tests/core/test_gc.in index ae94b0ec..55d98e60 100644 --- a/tests/core/test_gc.in +++ b/tests/core/test_gc.in @@ -1,107 +1,107 @@ +#include <stdio.h> +#include <gc.h> +#include <assert.h> - #include <stdio.h> - #include <gc.h> - #include <assert.h> +void *global; - void *global; +void finalizer(void *ptr, void *arg) { + printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); +} - void finalizer(void *ptr, void *arg) { - printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); - } +void finalizer2(void *ptr, void *arg) { + printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); +} - void finalizer2(void *ptr, void *arg) { - printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); - } +int main() { + GC_INIT(); - int main() { - GC_INIT(); + void *local, *local2, *local3, *local4, *local5, *local6; - void *local, *local2, *local3, *local4, *local5, *local6; + // Hold on to global, drop locals - // Hold on to global, drop locals + global = GC_MALLOC(1024); // rooted since in a static allocation + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + printf("alloc %p\n", global); - global = GC_MALLOC(1024); // rooted since in a static allocation - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - printf("alloc %p\n", global); + local = GC_MALLOC(1024); // not rooted since stack is not scanned + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void *)1, 0, 0); + printf("alloc %p\n", local); - local = GC_MALLOC(1024); // not rooted since stack is not scanned - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - printf("alloc %p\n", local); + assert((char *)local - (char *)global >= 1024 || + (char *)global - (char *)local >= 1024); - assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024); + local2 = GC_MALLOC(1024); // no finalizer + printf("alloc %p\n", local2); - local2 = GC_MALLOC(1024); // no finalizer - printf("alloc %p\n", local2); + local3 = GC_MALLOC(1024); // with finalizable2 + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void *)2, 0, 0); + printf("alloc %p\n", local); - local3 = GC_MALLOC(1024); // with finalizable2 - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0); - printf("alloc %p\n", local); + local4 = GC_MALLOC(1024); // yet another + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void *)3, 0, 0); + printf("alloc %p\n", local); - local4 = GC_MALLOC(1024); // yet another - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0); - printf("alloc %p\n", local); + printf("basic test\n"); - printf("basic test\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf("*\n"); - printf("*\n"); + GC_FREE(global); // force free will actually work - GC_FREE(global); // force free will actually work + // scanning inside objects - // scanning inside objects + global = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + local = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void *)1, 0, 0); + local2 = GC_MALLOC_ATOMIC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void *)2, 0, 0); + local3 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void *)3, 0, 0); + local4 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void *)4, 0, 0); + local5 = GC_MALLOC_UNCOLLECTABLE(12); + // This should never trigger since local5 is uncollectable + GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void *)5, 0, 0); - global = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - local = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - local2 = GC_MALLOC_ATOMIC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0); - local3 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0); - local4 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0); - local5 = GC_MALLOC_UNCOLLECTABLE(12); - // This should never trigger since local5 is uncollectable - GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0); + printf("heap size = %d\n", GC_get_heap_size()); - printf("heap size = %d\n", GC_get_heap_size()); + local4 = GC_REALLOC(local4, 24); - local4 = GC_REALLOC(local4, 24); + printf("heap size = %d\n", GC_get_heap_size()); - printf("heap size = %d\n", GC_get_heap_size()); + local6 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void *)6, 0, 0); + // This should be the same as a free + GC_REALLOC(local6, 0); - local6 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0); - // This should be the same as a free - GC_REALLOC(local6, 0); + void **globalData = (void **)global; + globalData[0] = local; + globalData[1] = local2; - void **globalData = (void**)global; - globalData[0] = local; - globalData[1] = local2; + void **localData = (void **)local; + localData[0] = local3; - void **localData = (void**)local; - localData[0] = local3; + void **local2Data = (void **)local2; + local2Data[0] = + local4; // actually ignored, because local2 is atomic, so 4 is freeable - void **local2Data = (void**)local2; - local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable + printf("object scan test test\n"); - printf("object scan test test\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf("*\n"); - printf("*\n"); + GC_FREE(global); // force free will actually work - GC_FREE(global); // force free will actually work + printf("*\n"); - printf("*\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf(".\n"); - printf(".\n"); + global = 0; - global = 0; - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_getgep.in b/tests/core/test_getgep.in index b92c4a1a..452942f9 100644 --- a/tests/core/test_getgep.in +++ b/tests/core/test_getgep.in @@ -1,17 +1,14 @@ +#include <stdio.h> +struct { + int y[10]; + int z[10]; +} commonblock; - #include <stdio.h> - struct { - int y[10]; - int z[10]; - } commonblock; - - int main() - { - for (int i = 0; i < 10; ++i) { - commonblock.y[i] = 1; - commonblock.z[i] = 2; - } - printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]); - return 0; - } -
\ No newline at end of file +int main() { + for (int i = 0; i < 10; ++i) { + commonblock.y[i] = 1; + commonblock.z[i] = 2; + } + printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]); + return 0; +} diff --git a/tests/core/test_getloadavg.in b/tests/core/test_getloadavg.in index 8365a9a1..c592985a 100644 --- a/tests/core/test_getloadavg.in +++ b/tests/core/test_getloadavg.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main() { - double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13}; - printf("ret: %d\n", getloadavg(load, 5)); - printf("load[0]: %.3lf\n", load[0]); - printf("load[1]: %.3lf\n", load[1]); - printf("load[2]: %.3lf\n", load[2]); - printf("load[3]: %.3lf\n", load[3]); - printf("load[4]: %.3lf\n", load[4]); - return 0; - } -
\ No newline at end of file +int main() { + double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13}; + printf("ret: %d\n", getloadavg(load, 5)); + printf("load[0]: %.3lf\n", load[0]); + printf("load[1]: %.3lf\n", load[1]); + printf("load[2]: %.3lf\n", load[2]); + printf("load[3]: %.3lf\n", load[3]); + printf("load[4]: %.3lf\n", load[4]); + return 0; +} diff --git a/tests/core/test_getopt.in b/tests/core/test_getopt.in index 1f03ef4e..6a678b79 100644 --- a/tests/core/test_getopt.in +++ b/tests/core/test_getopt.in @@ -1,45 +1,40 @@ - - #pragma clang diagnostic ignored "-Winvalid-pp-token" - #include <unistd.h> - #include <stdlib.h> - #include <stdio.h> - - int - main(int argc, char *argv[]) - { - int flags, opt; - int nsecs, tfnd; - - nsecs = 0; - tfnd = 0; - flags = 0; - while ((opt = getopt(argc, argv, "nt:")) != -1) { - switch (opt) { - case 'n': - flags = 1; - break; - case 't': - nsecs = atoi(optarg); - tfnd = 1; - break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", - argv[0]); - exit(EXIT_FAILURE); - } - } - - printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); - - if (optind >= argc) { - fprintf(stderr, "Expected argument after options\n"); - exit(EXIT_FAILURE); - } - - printf("name argument = %s\n", argv[optind]); - - /* Other code omitted */ - - exit(EXIT_SUCCESS); - } -
\ No newline at end of file +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char *argv[]) { + int flags, opt; + int nsecs, tfnd; + + nsecs = 0; + tfnd = 0; + flags = 0; + while ((opt = getopt(argc, argv, "nt:")) != -1) { + switch (opt) { + case 'n': + flags = 1; + break; + case 't': + nsecs = atoi(optarg); + tfnd = 1; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); + + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + exit(EXIT_FAILURE); + } + + printf("name argument = %s\n", argv[optind]); + + /* Other code omitted */ + + exit(EXIT_SUCCESS); +} diff --git a/tests/core/test_getopt_long.in b/tests/core/test_getopt_long.in index cc5c3e21..18f19f2e 100644 --- a/tests/core/test_getopt_long.in +++ b/tests/core/test_getopt_long.in @@ -1,82 +1,73 @@ +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#pragma clang diagnostic ignored "-Wdeprecated-writable-strings" +#include <stdio.h> /* for printf */ +#include <stdlib.h> /* for exit */ +#include <getopt.h> - #pragma clang diagnostic ignored "-Winvalid-pp-token" - #pragma clang diagnostic ignored "-Wdeprecated-writable-strings" - #include <stdio.h> /* for printf */ - #include <stdlib.h> /* for exit */ - #include <getopt.h> +int main(int argc, char **argv) { + int c; + int digit_optind = 0; - int - main(int argc, char **argv) - { - int c; - int digit_optind = 0; + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = { + {"add", required_argument, 0, 0}, + {"append", no_argument, 0, 0}, + {"delete", required_argument, 0, 0}, + {"verbose", no_argument, 0, 0}, + {"create", required_argument, 0, 'c'}, + {"file", required_argument, 0, 0}, + {0, 0, 0, 0}}; - while (1) { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = { - {"add", required_argument, 0, 0 }, - {"append", no_argument, 0, 0 }, - {"delete", required_argument, 0, 0 }, - {"verbose", no_argument, 0, 0 }, - {"create", required_argument, 0, 'c'}, - {"file", required_argument, 0, 0 }, - {0, 0, 0, 0 } - }; + c = getopt_long(argc, argv, "abc:d:012", long_options, &option_index); + if (c == -1) break; - c = getopt_long(argc, argv, "abc:d:012", - long_options, &option_index); - if (c == -1) - break; + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); + if (optarg) printf(" with arg %s", optarg); + printf("\n"); + break; - switch (c) { - case 0: - printf("option %s", long_options[option_index].name); - if (optarg) - printf(" with arg %s", optarg); - printf("\n"); - break; + case '0': + case '1': + case '2': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf("option %c\n", c); + break; - case '0': - case '1': - case '2': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf("option %c\n", c); - break; + case 'a': + printf("option a\n"); + break; - case 'a': - printf("option a\n"); - break; + case 'b': + printf("option b\n"); + break; - case 'b': - printf("option b\n"); - break; + case 'c': + printf("option c with value '%s'\n", optarg); + break; - case 'c': - printf("option c with value '%s'\n", optarg); - break; + case 'd': + printf("option d with value '%s'\n", optarg); + break; - case 'd': - printf("option d with value '%s'\n", optarg); - break; + case '?': + break; - case '?': - break; + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } - default: - printf("?? getopt returned character code 0%o ??\n", c); - } - } + if (optind < argc) { + printf("non-option ARGV-elements: "); + while (optind < argc) printf("%s ", argv[optind++]); + printf("\n"); + } - if (optind < argc) { - printf("non-option ARGV-elements: "); - while (optind < argc) - printf("%s ", argv[optind++]); - printf("\n"); - } - - exit(EXIT_SUCCESS); - } -
\ No newline at end of file + exit(EXIT_SUCCESS); +} diff --git a/tests/core/test_globaldoubles.in b/tests/core/test_globaldoubles.in index 45acc194..9ccfb521 100644 --- a/tests/core/test_globaldoubles.in +++ b/tests/core/test_globaldoubles.in @@ -1,26 +1,23 @@ +#include <stdlib.h> +#include <stdio.h> - #include <stdlib.h> - #include <stdio.h> +double testVu, testVv, testWu, testWv; - double testVu, testVv, testWu, testWv; +void Test(double _testVu, double _testVv, double _testWu, double _testWv) { + testVu = _testVu; + testVv = _testVv; + testWu = _testWu; + testWv = _testWv; + printf("BUG?\n"); + printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, + testWv); +} - void Test(double _testVu, double _testVv, double _testWu, double _testWv) - { - testVu = _testVu; - testVv = _testVv; - testWu = _testWu; - testWv = _testWv; - printf("BUG?\n"); - printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, testWv); - } - - int main(void) - { - double v1 = 465.1; - double v2 = 465.2; - double v3 = 160.3; - double v4 = 111.4; - Test(v1, v2, v3, v4); - return 0; - } -
\ No newline at end of file +int main(void) { + double v1 = 465.1; + double v2 = 465.2; + double v3 = 160.3; + double v4 = 111.4; + Test(v1, v2, v3, v4); + return 0; +} diff --git a/tests/core/test_globals.in b/tests/core/test_globals.in index ed5e7891..f972687a 100644 --- a/tests/core/test_globals.in +++ b/tests/core/test_globals.in @@ -1,13 +1,10 @@ +#include <stdio.h> - #include <stdio.h> +char cache[256], *next = cache; - char cache[256], *next = cache; - - int main() - { - cache[10] = 25; - next[20] = 51; - printf("*%d,%d*\n", next[10], cache[20]); - return 0; - } -
\ No newline at end of file +int main() { + cache[10] = 25; + next[20] = 51; + printf("*%d,%d*\n", next[10], cache[20]); + return 0; +} diff --git a/tests/core/test_gmtime.in b/tests/core/test_gmtime.in index 41ce87f9..7b7227ba 100644 --- a/tests/core/test_gmtime.in +++ b/tests/core/test_gmtime.in @@ -1,28 +1,26 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <assert.h> - #include <stdio.h> - #include <stdlib.h> - #include <time.h> - #include <assert.h> +int main(void) { + time_t t = time(NULL); + struct tm *ptm = gmtime(&t); + struct tm tmCurrent = *ptm; + int hour = tmCurrent.tm_hour; - int main(void) - { - time_t t=time(NULL); - struct tm *ptm=gmtime(&t); - struct tm tmCurrent=*ptm; - int hour=tmCurrent.tm_hour; - - t-=hour*3600; // back to midnight - int yday = -1; - for(hour=0;hour<24;hour++) - { - ptm=gmtime(&t); - // tm_yday must be constant all day... - printf("yday: %d, hour: %d\n", ptm->tm_yday, hour); - if (yday == -1) yday = ptm->tm_yday; - else assert(yday == ptm->tm_yday); - t+=3600; // add one hour - } - printf("ok!\n"); - return(0); - } -
\ No newline at end of file + t -= hour * 3600; // back to midnight + int yday = -1; + for (hour = 0; hour < 24; hour++) { + ptm = gmtime(&t); + // tm_yday must be constant all day... + printf("yday: %d, hour: %d\n", ptm->tm_yday, hour); + if (yday == -1) + yday = ptm->tm_yday; + else + assert(yday == ptm->tm_yday); + t += 3600; // add one hour + } + printf("ok!\n"); + return (0); +} diff --git a/tests/core/test_hello_world.in b/tests/core/test_hello_world.in index d9ca3acb..b1d9bbbc 100644 --- a/tests/core/test_hello_world.in +++ b/tests/core/test_hello_world.in @@ -1,8 +1,5 @@ - - #include <stdio.h> - int main() - { - printf("hello, world!\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + printf("hello, world!\n"); + return 0; +} diff --git a/tests/core/test_i16_emcc_intrinsic.in b/tests/core/test_i16_emcc_intrinsic.in index 54008cee..a2aa27ee 100644 --- a/tests/core/test_i16_emcc_intrinsic.in +++ b/tests/core/test_i16_emcc_intrinsic.in @@ -1,20 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +int test(unsigned short a, unsigned short b) { + unsigned short result = a; + result += b; + if (result < b) printf("C!"); + return result; +} - int test(unsigned short a, unsigned short b) { - unsigned short result = a; - result += b; - if (result < b) printf("C!"); - return result; - } - - int main(void) { - printf(",%d,", test(0, 0)); - printf(",%d,", test(1, 1)); - printf(",%d,", test(65535, 1)); - printf(",%d,", test(1, 65535)); - printf(",%d,", test(32768, 32767)); - printf(",%d,", test(32768, 32768)); - return 0; - } -
\ No newline at end of file +int main(void) { + printf(",%d,", test(0, 0)); + printf(",%d,", test(1, 1)); + printf(",%d,", test(65535, 1)); + printf(",%d,", test(1, 65535)); + printf(",%d,", test(32768, 32767)); + printf(",%d,", test(32768, 32768)); + return 0; +} diff --git a/tests/core/test_i32_mul_precise.in b/tests/core/test_i32_mul_precise.in index f045a768..2e62b4ba 100644 --- a/tests/core/test_i32_mul_precise.in +++ b/tests/core/test_i32_mul_precise.in @@ -1,11 +1,12 @@ +#include <stdio.h> - #include <stdio.h> - - int main(int argc, char **argv) { - unsigned long d1 = 0x847c9b5d; - unsigned long q = 0x549530e1; - if (argc > 1000) { q += argc; d1 -= argc; } // confuse optimizer - printf("%lu\n", d1*q); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + unsigned long d1 = 0x847c9b5d; + unsigned long q = 0x549530e1; + if (argc > 1000) { + q += argc; + d1 -= argc; + } // confuse optimizer + printf("%lu\n", d1 * q); + return 0; +} diff --git a/tests/core/test_i32_mul_semiprecise.in b/tests/core/test_i32_mul_semiprecise.in index c7b4cb96..a93a69da 100644 --- a/tests/core/test_i32_mul_semiprecise.in +++ b/tests/core/test_i32_mul_semiprecise.in @@ -1,28 +1,26 @@ +#include <stdio.h> - #include <stdio.h> +typedef unsigned int uint; - typedef unsigned int uint; +// from cube2, zlib licensed - // from cube2, zlib licensed +#define N (624) +#define M (397) +#define K (0x9908B0DFU) - #define N (624) - #define M (397) - #define K (0x9908B0DFU) +static uint state[N]; +static int next = N; - static uint state[N]; - static int next = N; +void seedMT(uint seed) { + state[0] = seed; + for (uint i = 1; i < N; i++) // if we do not do this precisely, at least we + // should coerce to int immediately, not wait + state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i; + next = 0; +} - void seedMT(uint seed) - { - state[0] = seed; - for(uint i = 1; i < N; i++) // if we do not do this precisely, at least we should coerce to int immediately, not wait - state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i; - next = 0; - } - - int main() { - seedMT(5497); - for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]); - return 0; - } -
\ No newline at end of file +int main() { + seedMT(5497); + for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]); + return 0; +} diff --git a/tests/core/test_i64_7z.in b/tests/core/test_i64_7z.in index 1d2f03a8..c15bfd78 100644 --- a/tests/core/test_i64_7z.in +++ b/tests/core/test_i64_7z.in @@ -1,17 +1,14 @@ - - #include <stdint.h> - #include <stdio.h> - uint64_t a, b; - int main(int argc, char *argv[]) - { - a = argc; - b = argv[1][0]; - printf("%d,%d\n", a, b); - if (a > a + b || a > a + b + 1) { - printf("one %lld, %lld", a, b); - return 0; - } - printf("zero %lld, %lld", a, b); - return 0; - } -
\ No newline at end of file +#include <stdint.h> +#include <stdio.h> +uint64_t a, b; +int main(int argc, char *argv[]) { + a = argc; + b = argv[1][0]; + printf("%d,%d\n", a, b); + if (a > a + b || a > a + b + 1) { + printf("one %lld, %lld", a, b); + return 0; + } + printf("zero %lld, %lld", a, b); + return 0; +} diff --git a/tests/core/test_i64_b.in b/tests/core/test_i64_b.in index b373a3aa..1cd87104 100644 --- a/tests/core/test_i64_b.in +++ b/tests/core/test_i64_b.in @@ -1,22 +1,20 @@ +#include <stdio.h> +#include <sys/time.h> - #include <stdio.h> - #include <sys/time.h> +typedef long long int64; - typedef long long int64; +#define PRMJ_USEC_PER_SEC 1000000L - #define PRMJ_USEC_PER_SEC 1000000L - - int main(int argc, char * argv[]) { - int64 sec = 1329409675 + argc; - int64 usec = 2329509675; - int64 mul = int64(sec) * PRMJ_USEC_PER_SEC; - int64 add = mul + int64(usec); - int add_low = add; - int add_high = add >> 32; - printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high); - int64 x = sec + (usec << 25); - x >>= argc*3; - printf("*%llu*\n", x); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + int64 sec = 1329409675 + argc; + int64 usec = 2329509675; + int64 mul = int64(sec) * PRMJ_USEC_PER_SEC; + int64 add = mul + int64(usec); + int add_low = add; + int add_high = add >> 32; + printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high); + int64 x = sec + (usec << 25); + x >>= argc * 3; + printf("*%llu*\n", x); + return 0; +} diff --git a/tests/core/test_i64_cmp.in b/tests/core/test_i64_cmp.in index b967d2ff..b9cadd4a 100644 --- a/tests/core/test_i64_cmp.in +++ b/tests/core/test_i64_cmp.in @@ -1,18 +1,14 @@ +#include <stdio.h> - #include <stdio.h> +typedef long long int64; - typedef long long int64; +bool compare(int64 val) { return val == -12; } - bool compare(int64 val) { - return val == -12; - } +bool compare2(int64 val) { return val < -12; } - bool compare2(int64 val) { - return val < -12; - } - - int main(int argc, char * argv[]) { - printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc-1-12), compare(1000+argc), compare2(argc-1-10), compare2(argc-1-14), compare2(argc+1000)); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc - 1 - 12), + compare(1000 + argc), compare2(argc - 1 - 10), compare2(argc - 1 - 14), + compare2(argc + 1000)); + return 0; +} diff --git a/tests/core/test_i64_cmp2.in b/tests/core/test_i64_cmp2.in index b285e1a1..8985e5a8 100644 --- a/tests/core/test_i64_cmp2.in +++ b/tests/core/test_i64_cmp2.in @@ -1,32 +1,28 @@ +#include <inttypes.h> +#include <stdio.h> - #include <inttypes.h> - #include <stdio.h> +typedef int32_t INT32; +typedef int64_t INT64; +typedef uint8_t UINT8; - typedef int32_t INT32; - typedef int64_t INT64; - typedef uint8_t UINT8; +void interface_clock_changed() { + UINT8 m_divshift; + INT32 m_divisor; - void interface_clock_changed() - { - UINT8 m_divshift; - INT32 m_divisor; + // INT64 attos = m_attoseconds_per_cycle; + INT64 attos = 279365114840; + m_divshift = 0; + while (attos >= (1UL << 31)) { + m_divshift++; + printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31); + attos >>= 1; + } + m_divisor = attos; - //INT64 attos = m_attoseconds_per_cycle; - INT64 attos = 279365114840; - m_divshift = 0; - while (attos >= (1UL << 31)) - { - m_divshift++; - printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31); - attos >>= 1; - } - m_divisor = attos; + printf("m_divisor is %i\n", m_divisor); +} - printf("m_divisor is %i\n",m_divisor); - } - - int main() { - interface_clock_changed(); - return 0; - } -
\ No newline at end of file +int main() { + interface_clock_changed(); + return 0; +} diff --git a/tests/core/test_i64_double.in b/tests/core/test_i64_double.in index 4b39355e..2b524971 100644 --- a/tests/core/test_i64_double.in +++ b/tests/core/test_i64_double.in @@ -1,38 +1,34 @@ +#include <stdio.h> - #include <stdio.h> +typedef long long int64; +#define JSDOUBLE_HI32_SIGNBIT 0x80000000 - typedef long long int64; - #define JSDOUBLE_HI32_SIGNBIT 0x80000000 +bool JSDOUBLE_IS_NEGZERO(double d) { + union { + struct { + unsigned int lo, hi; + } s; + double d; + } x; + if (d != 0) return false; + x.d = d; + return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0; +} - bool JSDOUBLE_IS_NEGZERO(double d) - { - union { - struct { - unsigned int lo, hi; - } s; - double d; - } x; - if (d != 0) - return false; - x.d = d; - return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0; - } +bool JSINT64_IS_NEGZERO(int64 l) { + union { + int64 i; + double d; + } x; + if (l != 0) return false; + x.i = l; + return x.d == -0; +} - bool JSINT64_IS_NEGZERO(int64 l) - { - union { - int64 i; - double d; - } x; - if (l != 0) - return false; - x.i = l; - return x.d == -0; - } - - int main(int argc, char * argv[]) { - printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1)); - printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1)); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), + JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1)); + printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), + JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1)); + return 0; +} diff --git a/tests/core/test_i64_i16.in b/tests/core/test_i64_i16.in index dcd9a69e..81d4a7bd 100644 --- a/tests/core/test_i64_i16.in +++ b/tests/core/test_i64_i16.in @@ -1,12 +1,10 @@ - - #include <stdint.h> - #include <stdio.h> - int main(int argc, char ** argv){ - int y=-133; - int64_t x= ((int64_t)((short)(y)))*(100 + argc); - if(x>0) - printf(">0\n"); - else - printf("<=0\n"); - } -
\ No newline at end of file +#include <stdint.h> +#include <stdio.h> +int main(int argc, char** argv) { + int y = -133; + int64_t x = ((int64_t)((short)(y))) * (100 + argc); + if (x > 0) + printf(">0\n"); + else + printf("<=0\n"); +} diff --git a/tests/core/test_i64_llabs.in b/tests/core/test_i64_llabs.in index 10961970..5d10bee0 100644 --- a/tests/core/test_i64_llabs.in +++ b/tests/core/test_i64_llabs.in @@ -1,9 +1,7 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main(int argc, char ** argv) { - printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); - return 0; - } -
\ No newline at end of file +int main(int argc, char** argv) { + printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); + return 0; +} diff --git a/tests/core/test_i64_qdouble.in b/tests/core/test_i64_qdouble.in index 1b8297e4..db47afa6 100644 --- a/tests/core/test_i64_qdouble.in +++ b/tests/core/test_i64_qdouble.in @@ -1,21 +1,14 @@ +#include <stdio.h> +typedef long long qint64; /* 64 bit signed */ +typedef double qreal; - #include <stdio.h> - typedef long long qint64; /* 64 bit signed */ - typedef double qreal; - - - int main(int argc, char **argv) - { - qreal c = 111; - qint64 d = -111 + (argc - 1); - c += d; - if (c < -1 || c > 1) - { - printf("Failed!\n"); - } - else - { - printf("Succeeded!\n"); - } - }; -
\ No newline at end of file +int main(int argc, char **argv) { + qreal c = 111; + qint64 d = -111 + (argc - 1); + c += d; + if (c < -1 || c > 1) { + printf("Failed!\n"); + } else { + printf("Succeeded!\n"); + } +}; diff --git a/tests/core/test_i64_umul.in b/tests/core/test_i64_umul.in index 4b4bdaca..bfe97154 100644 --- a/tests/core/test_i64_umul.in +++ b/tests/core/test_i64_umul.in @@ -1,20 +1,18 @@ +#include <inttypes.h> +#include <stdio.h> - #include <inttypes.h> - #include <stdio.h> +typedef uint32_t UINT32; +typedef uint64_t UINT64; - typedef uint32_t UINT32; - typedef uint64_t UINT64; +int main() { + volatile UINT32 testu32a = 2375724032U; + UINT32 bigu32 = 0xffffffffU; + volatile UINT64 testu64a = 14746250828952703000U; - int main() { - volatile UINT32 testu32a = 2375724032U; - UINT32 bigu32 = 0xffffffffU; - volatile UINT64 testu64a = 14746250828952703000U; + while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) { + printf("testu64a is %llu\n", testu64a); + testu64a /= 2; + } - while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) { - printf("testu64a is %llu\n", testu64a); - testu64a /= 2; - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in index 94982b51..7d2e4267 100644 --- a/tests/core/test_i64_varargs.in +++ b/tests/core/test_i64_varargs.in @@ -1,30 +1,29 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdint.h> - #include <stdarg.h> +int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, + ...) { + if (sig_start < 10123) printf("%s\n", msg + len); + va_list v; + va_start(v, sig_start); + if (sig_start > 1413) + printf("%d\n", va_arg(v, int)); + else + printf("nada\n"); + va_end(v); + return len * sig_start * (msg[0] + 1); +} - int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, ...) { - if (sig_start < 10123) - printf("%s\n", msg+len); - va_list v; - va_start(v, sig_start); - if (sig_start > 1413) - printf("%d\n", va_arg(v, int)); - else - printf("nada\n"); - va_end(v); - return len*sig_start*(msg[0]+1); - } - - int main(int argc, char **argv) - { - for (int i = 0; i < argc; i++) { - int64_t x; - if (i % 123123 == 0) - x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 54.111); - else - x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 13); - printf("%lld\n", x); - } - }; -
\ No newline at end of file +int main(int argc, char **argv) { + for (int i = 0; i < argc; i++) { + int64_t x; + if (i % 123123 == 0) + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 54.111); + else + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 13); + printf("%lld\n", x); + } +}; diff --git a/tests/core/test_i64_zextneg.in b/tests/core/test_i64_zextneg.in index 3f77131d..b7e204fe 100644 --- a/tests/core/test_i64_zextneg.in +++ b/tests/core/test_i64_zextneg.in @@ -1,16 +1,13 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main(int argc, char *argv[]) { + uint8_t byte = 0x80; + uint16_t two = byte; + uint32_t four = byte; + uint64_t eight = byte; - int main(int argc, char *argv[]) - { - uint8_t byte = 0x80; - uint16_t two = byte; - uint32_t four = byte; - uint64_t eight = byte; + printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); - printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_if.in b/tests/core/test_if.in index 20ed3a01..07edbe8d 100644 --- a/tests/core/test_if.in +++ b/tests/core/test_if.in @@ -1,11 +1,8 @@ - - #include <stdio.h> - int main() - { - int x = 5; - if (x > 3) { - printf("*yes*\n"); - } - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + if (x > 3) { + printf("*yes*\n"); + } + return 0; +} diff --git a/tests/core/test_if_else.in b/tests/core/test_if_else.in index 03b2bfa6..b7693eed 100644 --- a/tests/core/test_if_else.in +++ b/tests/core/test_if_else.in @@ -1,13 +1,10 @@ - - #include <stdio.h> - int main() - { - int x = 5; - if (x > 10) { - printf("*yes*\n"); - } else { - printf("*no*\n"); - } - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + if (x > 10) { + printf("*yes*\n"); + } else { + printf("*no*\n"); + } + return 0; +} diff --git a/tests/core/test_indirectbr.in b/tests/core/test_indirectbr.in index bdc66b53..ae3f1baa 100644 --- a/tests/core/test_indirectbr.in +++ b/tests/core/test_indirectbr.in @@ -1,21 +1,20 @@ +#include <stdio.h> +int main(void) { + const void *addrs[2] = {&&FOO, &&BAR}; - #include <stdio.h> - int main(void) { - const void *addrs[2] = { &&FOO, &&BAR }; + // confuse the optimizer so it doesn't hardcode the jump and avoid generating + // an |indirectbr| instruction + int which = 0; + for (int x = 0; x < 1000; x++) which = (which + x * x) % 7; + which = (which % 2) + 1; - // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction - int which = 0; - for (int x = 0; x < 1000; x++) which = (which + x*x) % 7; - which = (which % 2) + 1; + goto *addrs[which]; - goto *addrs[which]; - - FOO: - printf("bad\n"); - return 0; - BAR: - printf("good\n"); - const void *addr = &&FOO; - goto *addr; - } -
\ No newline at end of file +FOO: + printf("bad\n"); + return 0; +BAR: + printf("good\n"); + const void *addr = &&FOO; + goto *addr; +} diff --git a/tests/core/test_inherit.in b/tests/core/test_inherit.in index e9a152e8..ae5b819d 100644 --- a/tests/core/test_inherit.in +++ b/tests/core/test_inherit.in @@ -1,25 +1,22 @@ - - #include <stdio.h> - struct Parent { - int x1, x2; - }; - struct Child : Parent { - int y; - }; - int main() - { - Parent a; - a.x1 = 50; - a.x2 = 87; - Child b; - b.x1 = 78; - b.x2 = 550; - b.y = 101; - Child* c = (Child*)&a; - c->x1 ++; - c = &b; - c->y --; - printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct Parent { + int x1, x2; +}; +struct Child : Parent { + int y; +}; +int main() { + Parent a; + a.x1 = 50; + a.x2 = 87; + Child b; + b.x1 = 78; + b.x2 = 550; + b.y = 101; + Child* c = (Child*)&a; + c->x1++; + c = &b; + c->y--; + printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2); + return 0; +} diff --git a/tests/core/test_inlinejs.in b/tests/core/test_inlinejs.in index 0359b707..b6a98954 100644 --- a/tests/core/test_inlinejs.in +++ b/tests/core/test_inlinejs.in @@ -1,26 +1,27 @@ +#include <stdio.h> - #include <stdio.h> +double get() { + double ret = 0; + __asm __volatile__("Math.abs(-12/3.3)" : "=r"(ret)); // write to a variable + asm("#comment1"); + asm volatile("#comment2"); + asm volatile( + "#comment3\n" + "#comment4\n"); + return ret; +} - double get() { - double ret = 0; - __asm __volatile__("Math.abs(-12/3.3)":"=r"(ret)); // write to a variable - asm("#comment1"); - asm volatile("#comment2"); - asm volatile("#comment3\n" - "#comment4\n"); - return ret; - } +int main() { + asm("Module.print('Inline JS is very cool')"); + printf("%.2f\n", get()); - int main() { - asm("Module.print('Inline JS is very cool')"); - printf("%.2f\n", get()); + // Test that passing multiple input and output variables works. + int src1 = 1, src2 = 2, src3 = 3; + int dst1 = 0, dst2 = 0, dst3 = 0; + // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 + // = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): + // "r"(src1),"r"(src2),"r"(src3)); + // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3); - // Test that passing multiple input and output variables works. - int src1 = 1, src2 = 2, src3 = 3; - int dst1 = 0, dst2 = 0, dst3 = 0; - // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): "r"(src1),"r"(src2),"r"(src3)); - // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_inlinejs2.in b/tests/core/test_inlinejs2.in index 7a05fd67..438253c2 100644 --- a/tests/core/test_inlinejs2.in +++ b/tests/core/test_inlinejs2.in @@ -1,20 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +int mix(int x, int y) { + int ret; + asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write + return ret; +} - int mix(int x, int y) { - int ret; - asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write - return ret; - } +void mult() { + asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline + asm __volatile__("Module.print('done')"); +} - void mult() { - asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline - asm __volatile__("Module.print('done')"); - } - - int main(int argc, char **argv) { - printf("%d\n", mix(argc, argc/2)); - mult(); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + printf("%d\n", mix(argc, argc / 2)); + mult(); + return 0; +} diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in index e7d9b1e8..3e1913ff 100644 --- a/tests/core/test_inlinejs3.in +++ b/tests/core/test_inlinejs3.in @@ -1,26 +1,20 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - int main(int argc, char **argv) { - EM_ASM(Module.print('hello dere1')); - EM_ASM( - Module.print('hello dere2'); - ); - for (int i = 0; i < 3; i++) { - EM_ASM( - Module.print('hello dere3'); - Module.print('hello dere' + 4); - ); - } - int sum = 0; - for (int i = 0; i < argc*3; i++) { - sum += EM_ASM_INT({ - Module.print('i: ' + [$0, ($1).toFixed(2)]); - return $0*2; - }, i, double(i)/12); - } - printf("sum: %d\n", sum); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + EM_ASM(Module.print('hello dere1')); + EM_ASM(Module.print('hello dere2');); + for (int i = 0; i < 3; i++) { + EM_ASM(Module.print('hello dere3'); Module.print('hello dere' + 4);); + } + int sum = 0; + for (int i = 0; i < argc * 3; i++) { + sum += EM_ASM_INT({ + Module.print('i: ' + [ $0, ($1).toFixed(2) ]); + return $0 * 2; + }, + i, double(i) / 12); + } + printf("sum: %d\n", sum); + return 0; +} diff --git a/tests/core/test_intvars.in b/tests/core/test_intvars.in index 7cf7df89..27b4180b 100644 --- a/tests/core/test_intvars.in +++ b/tests/core/test_intvars.in @@ -1,50 +1,49 @@ +#include <stdio.h> +int global = 20; +int *far; +int main() { + int x = 5; + int y = x + 17; + int z = (y - 1) / 2; // Should stay an integer after division! + y += 1; + int w = x * 3 + 4; + int k = w < 15 ? 99 : 101; + far = &k; + *far += global; + int i = k > 100; // Should be an int, not a bool! + int j = i << 6; + j >>= 1; + j = j ^ 5; + int h = 1; + h |= 0; + int p = h; + p &= 0; + printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); - #include <stdio.h> - int global = 20; - int *far; - int main() - { - int x = 5; - int y = x+17; - int z = (y-1)/2; // Should stay an integer after division! - y += 1; - int w = x*3+4; - int k = w < 15 ? 99 : 101; - far = &k; - *far += global; - int i = k > 100; // Should be an int, not a bool! - int j = i << 6; - j >>= 1; - j = j ^ 5; - int h = 1; - h |= 0; - int p = h; - p &= 0; - printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); + long hash = -1; + size_t perturb; + int ii = 0; + for (perturb = hash;; perturb >>= 5) { + printf("%d:%d", ii, perturb); + ii++; + if (ii == 9) break; + printf(","); + } + printf("*\n"); + printf("*%.1d,%.2d*\n", 56, 9); - long hash = -1; - size_t perturb; - int ii = 0; - for (perturb = hash; ; perturb >>= 5) { - printf("%d:%d", ii, perturb); - ii++; - if (ii == 9) break; - printf(","); - } - printf("*\n"); - printf("*%.1d,%.2d*\n", 56, 9); + // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit + // shifts in JS + { + struct Fixed { + static int Mult(int a, int b) { + return ((long long)a * (long long)b) >> 16; + } + }; + printf("fixed:%d\n", Fixed::Mult(150000, 140000)); + } - // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS - { - struct Fixed { - static int Mult(int a, int b) { - return ((long long)a * (long long)b) >> 16; - } - }; - printf("fixed:%d\n", Fixed::Mult(150000, 140000)); - } - - printf("*%ld*%p\n", (long)21, &hash); // The %p should not enter an infinite loop! - return 0; - } -
\ No newline at end of file + printf("*%ld*%p\n", (long)21, + &hash); // The %p should not enter an infinite loop! + return 0; +} diff --git a/tests/core/test_isdigit_l.in b/tests/core/test_isdigit_l.in index b94f618d..069f2027 100644 --- a/tests/core/test_isdigit_l.in +++ b/tests/core/test_isdigit_l.in @@ -1,7 +1,5 @@ - - #include <iostream> - int main() { - using namespace std; - use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265); - } -
\ No newline at end of file +#include <iostream> +int main() { + using namespace std; + use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265); +} diff --git a/tests/core/test_isnan.in b/tests/core/test_isnan.in index d5ca7a6e..808ffa19 100644 --- a/tests/core/test_isnan.in +++ b/tests/core/test_isnan.in @@ -1,17 +1,16 @@ +#include <stdio.h> - #include <stdio.h> +int IsNaN(double x) { + int rc; /* The value return */ + volatile double y = x; + volatile double z = y; + rc = (y != z); + return rc; +} - int IsNaN(double x){ - int rc; /* The value return */ - volatile double y = x; - volatile double z = y; - rc = (y!=z); - return rc; - } - - int main() { - double tests[] = { 1.0, 3.333, 1.0/0.0, 0.0/0.0, -1.0/0.0, -0, 0, -123123123, 12.0E200 }; - for (int i = 0; i < sizeof(tests)/sizeof(double); i++) - printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i])); - } -
\ No newline at end of file +int main() { + double tests[] = {1.0, 3.333, 1.0 / 0.0, 0.0 / 0.0, -1.0 / 0.0, + -0, 0, -123123123, 12.0E200}; + for (int i = 0; i < sizeof(tests) / sizeof(double); i++) + printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i])); +} diff --git a/tests/core/test_istream.in b/tests/core/test_istream.in index 9a9d1c9a..e5988d24 100644 --- a/tests/core/test_istream.in +++ b/tests/core/test_istream.in @@ -1,16 +1,13 @@ +#include <string> +#include <sstream> +#include <iostream> - #include <string> - #include <sstream> - #include <iostream> +int main() { + std::string mystring("1 2 3"); + std::istringstream is(mystring); + int one, two, three; - int main() - { - std::string mystring("1 2 3"); - std::istringstream is(mystring); - int one, two, three; + is >> one >> two >> three; - is >> one >> two >> three; - - printf( "%i %i %i", one, two, three ); - } -
\ No newline at end of file + printf("%i %i %i", one, two, three); +} diff --git a/tests/core/test_iswdigit.in b/tests/core/test_iswdigit.in index cc1b4a74..74277a41 100644 --- a/tests/core/test_iswdigit.in +++ b/tests/core/test_iswdigit.in @@ -1,12 +1,10 @@ +#include <stdio.h> +#include <cctype> +#include <cwctype> - #include <stdio.h> - #include <cctype> - #include <cwctype> - - int main() { - using namespace std; - printf("%d ", isdigit('0')); - printf("%d ", iswdigit(L'0')); - return 0; - } -
\ No newline at end of file +int main() { + using namespace std; + printf("%d ", isdigit('0')); + printf("%d ", iswdigit(L'0')); + return 0; +} diff --git a/tests/core/test_libcextra.in b/tests/core/test_libcextra.in index e0ff2f8e..ebeb8b50 100644 --- a/tests/core/test_libcextra.in +++ b/tests/core/test_libcextra.in @@ -1,13 +1,10 @@ +#include <stdio.h> +#include <wchar.h> - #include <stdio.h> - #include <wchar.h> +int main() { + const wchar_t* wstr = L"Hello"; - int main() - { - const wchar_t* wstr = L"Hello"; + printf("wcslen: %d\n", wcslen(wstr)); - printf("wcslen: %d\n", wcslen(wstr)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_libgen.in b/tests/core/test_libgen.in index c7918a78..d62e4a00 100644 --- a/tests/core/test_libgen.in +++ b/tests/core/test_libgen.in @@ -1,41 +1,39 @@ +#include <stdio.h> +#include <libgen.h> - #include <stdio.h> - #include <libgen.h> +int main() { + char p1[16] = "/usr/lib", p1x[16] = "/usr/lib"; + printf("%s -> ", p1); + printf("%s : %s\n", dirname(p1x), basename(p1)); - int main() { - char p1[16] = "/usr/lib", p1x[16] = "/usr/lib"; - printf("%s -> ", p1); - printf("%s : %s\n", dirname(p1x), basename(p1)); + char p2[16] = "/usr", p2x[16] = "/usr"; + printf("%s -> ", p2); + printf("%s : %s\n", dirname(p2x), basename(p2)); - char p2[16] = "/usr", p2x[16] = "/usr"; - printf("%s -> ", p2); - printf("%s : %s\n", dirname(p2x), basename(p2)); + char p3[16] = "/usr/", p3x[16] = "/usr/"; + printf("%s -> ", p3); + printf("%s : %s\n", dirname(p3x), basename(p3)); - char p3[16] = "/usr/", p3x[16] = "/usr/"; - printf("%s -> ", p3); - printf("%s : %s\n", dirname(p3x), basename(p3)); + char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///"; + printf("%s -> ", p4); + printf("%s : %s\n", dirname(p4x), basename(p4)); - char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///"; - printf("%s -> ", p4); - printf("%s : %s\n", dirname(p4x), basename(p4)); + char p5[16] = "/", p5x[16] = "/"; + printf("%s -> ", p5); + printf("%s : %s\n", dirname(p5x), basename(p5)); - char p5[16] = "/", p5x[16] = "/"; - printf("%s -> ", p5); - printf("%s : %s\n", dirname(p5x), basename(p5)); + char p6[16] = "///", p6x[16] = "///"; + printf("%s -> ", p6); + printf("%s : %s\n", dirname(p6x), basename(p6)); - char p6[16] = "///", p6x[16] = "///"; - printf("%s -> ", p6); - printf("%s : %s\n", dirname(p6x), basename(p6)); + char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/.."; + printf("%s -> ", p7); + printf("%s : %s\n", dirname(p7x), basename(p7)); - char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/.."; - printf("%s -> ", p7); - printf("%s : %s\n", dirname(p7x), basename(p7)); + char p8[16] = "", p8x[16] = ""; + printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8)); - char p8[16] = "", p8x[16] = ""; - printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8)); + printf("(null) -> %s : %s\n", dirname(0), basename(0)); - printf("(null) -> %s : %s\n", dirname(0), basename(0)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_linked_list.in b/tests/core/test_linked_list.in index 4ca978bf..c3d457dd 100644 --- a/tests/core/test_linked_list.in +++ b/tests/core/test_linked_list.in @@ -1,42 +1,39 @@ +#include <stdio.h> +struct worker_args { + int value; + struct worker_args* next; +}; +int main() { + worker_args a; + worker_args b; + a.value = 60; + a.next = &b; + b.value = 900; + b.next = NULL; + worker_args* c = &a; + int total = 0; + while (c) { + total += c->value; + c = c->next; + } - #include <stdio.h> - struct worker_args { - int value; - struct worker_args *next; - }; - int main() - { - worker_args a; - worker_args b; - a.value = 60; - a.next = &b; - b.value = 900; - b.next = NULL; - worker_args* c = &a; - int total = 0; - while (c) { - total += c->value; - c = c->next; - } + // Chunk of em + worker_args chunk[10]; + for (int i = 0; i < 9; i++) { + chunk[i].value = i * 10; + chunk[i].next = &chunk[i + 1]; + } + chunk[9].value = 90; + chunk[9].next = &chunk[0]; - // Chunk of em - worker_args chunk[10]; - for (int i = 0; i < 9; i++) { - chunk[i].value = i*10; - chunk[i].next = &chunk[i+1]; - } - chunk[9].value = 90; - chunk[9].next = &chunk[0]; + c = chunk; + do { + total += c->value; + c = c->next; + } while (c != chunk); - c = chunk; - do { - total += c->value; - c = c->next; - } while (c != chunk); + printf("*%d,%d*\n", total, b.next); + // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) - printf("*%d,%d*\n", total, b.next); - // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_llrint.in b/tests/core/test_llrint.in index cbba8a21..2744c73a 100644 --- a/tests/core/test_llrint.in +++ b/tests/core/test_llrint.in @@ -1,8 +1,7 @@ - - #include <stdio.h> - #include <math.h> - int main() { - printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667)); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <math.h> +int main() { + printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), + llrint(1099511627776.667)); + return 0; +} diff --git a/tests/core/test_llvm_intrinsics.in b/tests/core/test_llvm_intrinsics.in index 6c235bdf..2bc87a54 100644 --- a/tests/core/test_llvm_intrinsics.in +++ b/tests/core/test_llvm_intrinsics.in @@ -1,41 +1,44 @@ - - #include <stdio.h> - #include <sys/types.h> - - extern "C" { - extern unsigned short llvm_bswap_i16(unsigned short x); - extern unsigned int llvm_bswap_i32(unsigned int x); - extern int32_t llvm_ctlz_i32(int32_t x); - extern int64_t llvm_ctlz_i64(int64_t x); - extern int32_t llvm_cttz_i32(int32_t x); - extern int64_t llvm_cttz_i64(int64_t x); - extern int32_t llvm_ctpop_i32(int32_t x); - extern int64_t llvm_ctpop_i64(int64_t x); - extern int llvm_expect_i32(int x, int y); - } - - int main(void) { - unsigned short x = 0xc8ef; - printf("%x,%x\n", x&0xff, x >> 8); - x = llvm_bswap_i16(x); - printf("%x,%x\n", x&0xff, x >> 8); - - unsigned int y = 0xc5de158a; - printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff); - y = llvm_bswap_i32(y); - printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff); - - printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10)); - printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10)); - printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101)); - printf("%d\n", (int)llvm_ctpop_i32(-594093059)); - - printf("%d\n", llvm_expect_i32(x % 27, 3)); - - int64_t a = 1; - a = __builtin_bswap64(a); - printf("%lld\n", a); - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <sys/types.h> + +extern "C" { +extern unsigned short llvm_bswap_i16(unsigned short x); +extern unsigned int llvm_bswap_i32(unsigned int x); +extern int32_t llvm_ctlz_i32(int32_t x); +extern int64_t llvm_ctlz_i64(int64_t x); +extern int32_t llvm_cttz_i32(int32_t x); +extern int64_t llvm_cttz_i64(int64_t x); +extern int32_t llvm_ctpop_i32(int32_t x); +extern int64_t llvm_ctpop_i64(int64_t x); +extern int llvm_expect_i32(int x, int y); +} + +int main(void) { + unsigned short x = 0xc8ef; + printf("%x,%x\n", x & 0xff, x >> 8); + x = llvm_bswap_i16(x); + printf("%x,%x\n", x & 0xff, x >> 8); + + unsigned int y = 0xc5de158a; + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + y = llvm_bswap_i32(y); + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + + printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), + llvm_ctlz_i32(1 << 10)); + printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), + llvm_cttz_i32(1 << 10)); + printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), + llvm_ctpop_i32(0x3101)); + printf("%d\n", (int)llvm_ctpop_i32(-594093059)); + + printf("%d\n", llvm_expect_i32(x % 27, 3)); + + int64_t a = 1; + a = __builtin_bswap64(a); + printf("%lld\n", a); + + return 0; +} diff --git a/tests/core/test_llvm_used.in b/tests/core/test_llvm_used.in index e40ae09e..b3c9f10e 100644 --- a/tests/core/test_llvm_used.in +++ b/tests/core/test_llvm_used.in @@ -1,14 +1,13 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - extern "C" { - EMSCRIPTEN_KEEPALIVE void foobar(int x) { - printf("Worked! %d\n", x); - } - } +extern "C" { + EMSCRIPTEN_KEEPALIVE void foobar(int x) { + printf("Worked! %d\n", x); + } +} - int main() { - emscripten_run_script("Module['_foobar'](10)"); - return 0; - }
\ No newline at end of file +int main() { + emscripten_run_script("Module['_foobar'](10)"); + return 0; +} diff --git a/tests/core/test_llvmswitch.in b/tests/core/test_llvmswitch.in index 64cfa652..b3f871e4 100644 --- a/tests/core/test_llvmswitch.in +++ b/tests/core/test_llvmswitch.in @@ -1,24 +1,23 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +int switcher(int p) { + switch (p) { + case 'a': + case 'b': + case 'c': + return p - 1; + case -15: + return p + 1; + } + return p; +} - int switcher(int p) - { - switch(p) { - case 'a': - case 'b': - case 'c': - return p-1; - case -15: - return p+1; - } - return p; - } - - int main( int argc, const char *argv[] ) { - unsigned int x = 0xfffffff1; - x >>= (argc-1); // force it to be unsigned for purpose of checking our switch comparison in signed/unsigned - printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), switcher(x), switcher(-15), switcher('e')); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + unsigned int x = 0xfffffff1; + x >>= (argc - 1); // force it to be unsigned for purpose of checking our + // switch comparison in signed/unsigned + printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), + switcher(x), switcher(-15), switcher('e')); + return 0; +} diff --git a/tests/core/test_longjmp.in b/tests/core/test_longjmp.in index 4260ed15..44940cdd 100644 --- a/tests/core/test_longjmp.in +++ b/tests/core/test_longjmp.in @@ -1,34 +1,33 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; +void second(void) { + printf("second\n"); + longjmp(buf, -1); +} - void second(void) { - printf("second\n"); - longjmp(buf,-1); - } +void first(void) { + printf("first\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} - void first(void) { - printf("first\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 - } +int main() { + volatile int x = 0; + int jmpval = setjmp(buf); + if (!jmpval) { + x++; // should be properly restored once longjmp jumps back + first(); // when executed, setjmp returns 1 + printf("skipped\n"); // does not print + } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 + printf("result: %d %d\n", x, jmpval); // prints + x++; + second(); // when executed, setjmp returns -1 + } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 + printf("result: %d %d\n", x, jmpval); // prints + } - int main() { - volatile int x = 0; - int jmpval = setjmp(buf); - if (!jmpval) { - x++; // should be properly restored once longjmp jumps back - first(); // when executed, setjmp returns 1 - printf("skipped\n"); // does not print - } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 - printf("result: %d %d\n", x, jmpval); // prints - x++; - second(); // when executed, setjmp returns -1 - } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 - printf("result: %d %d\n", x, jmpval); // prints - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp2.in b/tests/core/test_longjmp2.in index ef73c8ba..e09a33f7 100644 --- a/tests/core/test_longjmp2.in +++ b/tests/core/test_longjmp2.in @@ -1,37 +1,35 @@ - - #include <setjmp.h> - #include <stdio.h> - - typedef struct { - jmp_buf* jmp; - } jmp_state; - - void stack_manipulate_func(jmp_state* s, int level) { - jmp_buf buf; - - printf("Entering stack_manipulate_func, level: %d\n", level); - - if (level == 0) { - s->jmp = &buf; - if (setjmp(*(s->jmp)) == 0) { - printf("Setjmp normal execution path, level: %d\n", level); - stack_manipulate_func(s, level + 1); - } else { - printf("Setjmp error execution path, level: %d\n", level); - } - } else { - printf("Perform longjmp at level %d\n", level); - longjmp(*(s->jmp), 1); - } - - printf("Exiting stack_manipulate_func, level: %d\n", level); - } - - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; - stack_manipulate_func(&s, 0); - - return 0; - } -
\ No newline at end of file +#include <setjmp.h> +#include <stdio.h> + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void stack_manipulate_func(jmp_state* s, int level) { + jmp_buf buf; + + printf("Entering stack_manipulate_func, level: %d\n", level); + + if (level == 0) { + s->jmp = &buf; + if (setjmp(*(s->jmp)) == 0) { + printf("Setjmp normal execution path, level: %d\n", level); + stack_manipulate_func(s, level + 1); + } else { + printf("Setjmp error execution path, level: %d\n", level); + } + } else { + printf("Perform longjmp at level %d\n", level); + longjmp(*(s->jmp), 1); + } + + printf("Exiting stack_manipulate_func, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + stack_manipulate_func(&s, 0); + + return 0; +} diff --git a/tests/core/test_longjmp3.in b/tests/core/test_longjmp3.in index 95fcf36c..f9b88469 100644 --- a/tests/core/test_longjmp3.in +++ b/tests/core/test_longjmp3.in @@ -1,42 +1,40 @@ - - #include <setjmp.h> - #include <stdio.h> - - typedef struct { - jmp_buf* jmp; - } jmp_state; - - void setjmp_func(jmp_state* s, int level) { - jmp_buf* prev_jmp = s->jmp; - jmp_buf c_jmp; - - if (level == 2) { - printf("level is 2, perform longjmp!\n"); - longjmp(*(s->jmp), 1); - } - - if (setjmp(c_jmp) == 0) { - printf("setjmp normal execution path, level: %d\n", level); - s->jmp = &c_jmp; - setjmp_func(s, level + 1); - } else { - printf("setjmp exception execution path, level: %d\n", level); - if (prev_jmp) { - printf("prev_jmp is not empty, continue with longjmp!\n"); - s->jmp = prev_jmp; - longjmp(*(s->jmp), 1); - } - } - - printf("Exiting setjmp function, level: %d\n", level); - } - - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; - - setjmp_func(&s, 0); - - return 0; - } -
\ No newline at end of file +#include <setjmp.h> +#include <stdio.h> + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void setjmp_func(jmp_state* s, int level) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + longjmp(*(s->jmp), 1); + } + + if (setjmp(c_jmp) == 0) { + printf("setjmp normal execution path, level: %d\n", level); + s->jmp = &c_jmp; + setjmp_func(s, level + 1); + } else { + printf("setjmp exception execution path, level: %d\n", level); + if (prev_jmp) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + longjmp(*(s->jmp), 1); + } + } + + printf("Exiting setjmp function, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + + setjmp_func(&s, 0); + + return 0; +} diff --git a/tests/core/test_longjmp4.in b/tests/core/test_longjmp4.in index ce27f751..68fa4c22 100644 --- a/tests/core/test_longjmp4.in +++ b/tests/core/test_longjmp4.in @@ -1,44 +1,40 @@ +#include <setjmp.h> +#include <stdio.h> - #include <setjmp.h> - #include <stdio.h> +typedef struct { + jmp_buf* jmp; +} jmp_state; - typedef struct { - jmp_buf* jmp; - } jmp_state; +void second_func(jmp_state* s); - void second_func(jmp_state* s); +void first_func(jmp_state* s) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + volatile int once = 0; - void first_func(jmp_state* s) { - jmp_buf* prev_jmp = s->jmp; - jmp_buf c_jmp; - volatile int once = 0; + if (setjmp(c_jmp) == 0) { + printf("Normal execution path of first function!\n"); - if (setjmp(c_jmp) == 0) { - printf("Normal execution path of first function!\n"); + s->jmp = &c_jmp; + second_func(s); + } else { + printf("Exception execution path of first function! %d\n", once); - s->jmp = &c_jmp; - second_func(s); - } else { - printf("Exception execution path of first function! %d\n", once); + if (!once) { + printf("Calling longjmp the second time!\n"); + once = 1; + longjmp(*(s->jmp), 1); + } + } +} - if (!once) { - printf("Calling longjmp the second time!\n"); - once = 1; - longjmp(*(s->jmp), 1); - } - } - } +void second_func(jmp_state* s) { longjmp(*(s->jmp), 1); } - void second_func(jmp_state* s) { - longjmp(*(s->jmp), 1); - } +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; + first_func(&s); - first_func(&s); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp_exc.in b/tests/core/test_longjmp_exc.in index 3fc07b85..4e568242 100644 --- a/tests/core/test_longjmp_exc.in +++ b/tests/core/test_longjmp_exc.in @@ -1,28 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <setjmp.h> +#include <emscripten.h> - #include <stdlib.h> - #include <stdio.h> - #include <setjmp.h> - #include <emscripten.h> +jmp_buf abortframe; - jmp_buf abortframe; +void dostuff(int a) { + printf("pre\n"); + if (a != 42) + emscripten_run_script( + "waka_waka()"); // this should fail, and never reach "never" + printf("never\n"); - void dostuff(int a) { - printf("pre\n"); - if (a != 42) emscripten_run_script("waka_waka()"); // this should fail, and never reach "never" - printf("never\n"); + if (a == 100) { + longjmp(abortframe, -1); + } - if (a == 100) { - longjmp (abortframe, -1); - } + if (setjmp(abortframe)) { + printf("got 100"); + } +} - if (setjmp(abortframe)) { - printf("got 100"); - } - } - - int main(int argc, char **argv) { - dostuff(argc); - exit(1); - return 1; - } -
\ No newline at end of file +int main(int argc, char **argv) { + dostuff(argc); + exit(1); + return 1; +} diff --git a/tests/core/test_longjmp_funcptr.in b/tests/core/test_longjmp_funcptr.in index e699bae6..38cbd86e 100644 --- a/tests/core/test_longjmp_funcptr.in +++ b/tests/core/test_longjmp_funcptr.in @@ -1,32 +1,31 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; +void (*fp)() = NULL; - void (*fp)() = NULL; +void second(void) { + printf("second\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} - void second(void) { - printf("second\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 - } +void first(void) { + fp(); + printf("first\n"); // does not print +} - void first(void) { - fp(); - printf("first\n"); // does not print - } +int main(int argc, char **argv) { + fp = argc == 200 ? NULL : second; - int main(int argc, char **argv) { - fp = argc == 200 ? NULL : second; + volatile int x = 0; + if (!setjmp(buf)) { + x++; + first(); // when executed, setjmp returns 0 + } else { // when longjmp jumps back, setjmp returns 1 + printf("main: %d\n", x); // prints + } - volatile int x = 0; - if ( ! setjmp(buf) ) { - x++; - first(); // when executed, setjmp returns 0 - } else { // when longjmp jumps back, setjmp returns 1 - printf("main: %d\n", x); // prints - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp_repeat.in b/tests/core/test_longjmp_repeat.in index 4476f8dd..f782fc0c 100644 --- a/tests/core/test_longjmp_repeat.in +++ b/tests/core/test_longjmp_repeat.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; - - int main() { - volatile int x = 0; - printf("setjmp:%d\n", setjmp(buf)); - x++; - printf("x:%d\n", x); - if (x < 4) longjmp(buf, x*2); - return 0; - } -
\ No newline at end of file +int main() { + volatile int x = 0; + printf("setjmp:%d\n", setjmp(buf)); + x++; + printf("x:%d\n", x); + if (x < 4) longjmp(buf, x * 2); + return 0; +} diff --git a/tests/core/test_longjmp_stacked.in b/tests/core/test_longjmp_stacked.in index 19539561..b7fd6bfa 100644 --- a/tests/core/test_longjmp_stacked.in +++ b/tests/core/test_longjmp_stacked.in @@ -1,44 +1,42 @@ +#include <stdio.h> +#include <setjmp.h> +#include <stdlib.h> +#include <string.h> - #include <stdio.h> - #include <setjmp.h> - #include <stdlib.h> - #include <string.h> +int bottom, top; - int bottom, top; +int run(int y) { + // confuse stack + char *s = (char *)alloca(100); + memset(s, 1, 100); + s[y] = y; + s[y / 2] = y * 2; + volatile int x = s[y]; + top = (int)alloca(4); + if (x <= 2) return x; + jmp_buf buf; + printf("setjmp of %d\n", x); + if (setjmp(buf) == 0) { + printf("going\n"); + x += run(x / 2); + longjmp(buf, 1); + } + printf("back\n"); + return x / 2; +} - int run(int y) { - // confuse stack - char *s = (char*)alloca(100); - memset(s, 1, 100); - s[y] = y; - s[y/2] = y*2; - volatile int x = s[y]; - top = (int)alloca(4); - if (x <= 2) return x; - jmp_buf buf; - printf("setjmp of %d\n", x); - if (setjmp(buf) == 0) { - printf("going\n"); - x += run(x/2); - longjmp(buf, 1); - } - printf("back\n"); - return x/2; - } - - int main(int argc, char **argv) { - int sum = 0; - for (int i = 0; i < argc*2; i++) { - bottom = (int)alloca(4); - sum += run(10); - // scorch the earth - if (bottom < top) { - memset((void*)bottom, 1, top - bottom); - } else { - memset((void*)top, 1, bottom - top); - } - } - printf("%d\n", sum); - return sum; - } -
\ No newline at end of file +int main(int argc, char **argv) { + int sum = 0; + for (int i = 0; i < argc * 2; i++) { + bottom = (int)alloca(4); + sum += run(10); + // scorch the earth + if (bottom < top) { + memset((void *)bottom, 1, top - bottom); + } else { + memset((void *)top, 1, bottom - top); + } + } + printf("%d\n", sum); + return sum; +} diff --git a/tests/core/test_loop.in b/tests/core/test_loop.in index 9df45457..83721d17 100644 --- a/tests/core/test_loop.in +++ b/tests/core/test_loop.in @@ -1,17 +1,14 @@ - - #include <stdio.h> - int main() - { - int x = 5; - for (int i = 0; i < 6; i++) { - x += x*i; - if (x > 1000) { - if (x % 7 == 0) printf("cheez\n"); - x /= 2; - break; - } - } - printf("*%d*\n", x); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + for (int i = 0; i < 6; i++) { + x += x * i; + if (x > 1000) { + if (x % 7 == 0) printf("cheez\n"); + x /= 2; + break; + } + } + printf("*%d*\n", x); + return 0; +} diff --git a/tests/core/test_mainenv.in b/tests/core/test_mainenv.in index da434196..f42c6b59 100644 --- a/tests/core/test_mainenv.in +++ b/tests/core/test_mainenv.in @@ -1,8 +1,5 @@ - - #include <stdio.h> - int main(int argc, char **argv, char **envp) - { - printf("*%p*\n", envp); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main(int argc, char **argv, char **envp) { + printf("*%p*\n", envp); + return 0; +} diff --git a/tests/core/test_math.in b/tests/core/test_math.in index 0685c178..e638404b 100644 --- a/tests/core/test_math.in +++ b/tests/core/test_math.in @@ -1,34 +1,34 @@ - - #include <stdio.h> - #include <stdlib.h> - #include <cmath> - int main(int argc, char **argv) - { - printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1/0.0) > 1e300); // could end up as infinity, or just a very very big number - printf(",%d", isfinite(NAN) != 0); - printf(",%d", isfinite(INFINITY) != 0); - printf(",%d", isfinite(-INFINITY) != 0); - printf(",%d", isfinite(12.3) != 0); - printf(",%d", isinf(NAN) != 0); - printf(",%d", isinf(INFINITY) != 0); - printf(",%d", isinf(-INFINITY) != 0); - printf(",%d", isinf(12.3) != 0); - div_t div_result = div(23, 10); - printf(",%d", div_result.quot); - printf(",%d", div_result.rem); - double sine = -1.0, cosine = -1.0; - sincos(0.0, &sine, &cosine); - printf(",%1.1lf", sine); - printf(",%1.1lf", cosine); - float fsine = -1.0f, fcosine = -1.0f; - sincosf(0.0, &fsine, &fcosine); - printf(",%1.1f", fsine); - printf(",%1.1f", fcosine); - fsine = sinf(1.1 + argc - 1); - fcosine = cosf(1.1 + argc - 1); - printf(",%1.1f", fsine); - printf(",%1.1f", fcosine); - printf("*\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> +#include <cmath> +int main(int argc, char **argv) { + printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1 / 0.0) > 1e300); // could end up as + // infinity, or just + // a very very big + // number + printf(",%d", isfinite(NAN) != 0); + printf(",%d", isfinite(INFINITY) != 0); + printf(",%d", isfinite(-INFINITY) != 0); + printf(",%d", isfinite(12.3) != 0); + printf(",%d", isinf(NAN) != 0); + printf(",%d", isinf(INFINITY) != 0); + printf(",%d", isinf(-INFINITY) != 0); + printf(",%d", isinf(12.3) != 0); + div_t div_result = div(23, 10); + printf(",%d", div_result.quot); + printf(",%d", div_result.rem); + double sine = -1.0, cosine = -1.0; + sincos(0.0, &sine, &cosine); + printf(",%1.1lf", sine); + printf(",%1.1lf", cosine); + float fsine = -1.0f, fcosine = -1.0f; + sincosf(0.0, &fsine, &fcosine); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + fsine = sinf(1.1 + argc - 1); + fcosine = cosf(1.1 + argc - 1); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + printf("*\n"); + return 0; +} diff --git a/tests/core/test_mathfuncptr.in b/tests/core/test_mathfuncptr.in index 96e78401..87feaade 100644 --- a/tests/core/test_mathfuncptr.in +++ b/tests/core/test_mathfuncptr.in @@ -1,13 +1,11 @@ +#include <math.h> +#include <stdio.h> - #include <math.h> - #include <stdio.h> - - int - main(int argc, char **argv) { - float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; - float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; - float (*fn3)(float) = argc != 14 ? &erff : &fabsf; - printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), fn3(10)); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; + float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; + float (*fn3)(float) = argc != 14 ? &erff : &fabsf; + printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), + fn3(10)); + return 0; +} diff --git a/tests/core/test_memcpy2.in b/tests/core/test_memcpy2.in index 91e0b6a0..c7b4de89 100644 --- a/tests/core/test_memcpy2.in +++ b/tests/core/test_memcpy2.in @@ -1,22 +1,20 @@ - - #include <stdio.h> - #include <string.h> - #include <assert.h> - int main() { - char buffer[256]; - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - for (int k = 0; k < 35; k++) { - for (int t = 0; t < 256; t++) buffer[t] = t; - char *dest = buffer + i + 128; - char *src = buffer+j; - //printf("%d, %d, %d\n", i, j, k); - assert(memcpy(dest, src, k) == dest); - assert(memcmp(dest, src, k) == 0); - } - } - } - printf("ok.\n"); - return 1; +#include <stdio.h> +#include <string.h> +#include <assert.h> +int main() { + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i + 128; + char *src = buffer + j; + // printf("%d, %d, %d\n", i, j, k); + assert(memcpy(dest, src, k) == dest); + assert(memcmp(dest, src, k) == 0); } -
\ No newline at end of file + } + } + printf("ok.\n"); + return 1; +} diff --git a/tests/core/test_memcpy_memcmp.in b/tests/core/test_memcpy_memcmp.in index c89d7ef6..fb5dfe6f 100644 --- a/tests/core/test_memcpy_memcmp.in +++ b/tests/core/test_memcpy_memcmp.in @@ -1,45 +1,43 @@ +#include <stdio.h> +#include <string.h> +#include <assert.h> - #include <stdio.h> - #include <string.h> - #include <assert.h> - - #define MAXX 48 - void reset(unsigned char *buffer) { - for (int i = 0; i < MAXX; i++) buffer[i] = i+1; - } - void dump(unsigned char *buffer) { - for (int i = 0; i < MAXX-1; i++) printf("%2d,", buffer[i]); - printf("%d\n", buffer[MAXX-1]); +#define MAXX 48 +void reset(unsigned char *buffer) { + for (int i = 0; i < MAXX; i++) buffer[i] = i + 1; +} +void dump(unsigned char *buffer) { + for (int i = 0; i < MAXX - 1; i++) printf("%2d,", buffer[i]); + printf("%d\n", buffer[MAXX - 1]); +} +int main() { + unsigned char buffer[MAXX]; + for (int i = MAXX / 4; i < MAXX - MAXX / 4; i++) { + for (int j = MAXX / 4; j < MAXX - MAXX / 4; j++) { + for (int k = 1; k < MAXX / 4; k++) { + if (i == j) continue; + if (i < j && i + k > j) continue; + if (j < i && j + k > i) continue; + printf("[%d,%d,%d] ", i, j, k); + reset(buffer); + memcpy(buffer + i, buffer + j, k); + dump(buffer); + assert(memcmp(buffer + i, buffer + j, k) == 0); + buffer[i + k / 2]++; + if (buffer[i + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) > 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) < 0); } - int main() { - unsigned char buffer[MAXX]; - for (int i = MAXX/4; i < MAXX-MAXX/4; i++) { - for (int j = MAXX/4; j < MAXX-MAXX/4; j++) { - for (int k = 1; k < MAXX/4; k++) { - if (i == j) continue; - if (i < j && i+k > j) continue; - if (j < i && j+k > i) continue; - printf("[%d,%d,%d] ", i, j, k); - reset(buffer); - memcpy(buffer+i, buffer+j, k); - dump(buffer); - assert(memcmp(buffer+i, buffer+j, k) == 0); - buffer[i + k/2]++; - if (buffer[i + k/2] != 0) { - assert(memcmp(buffer+i, buffer+j, k) > 0); - } else { - assert(memcmp(buffer+i, buffer+j, k) < 0); - } - buffer[i + k/2]--; - buffer[j + k/2]++; - if (buffer[j + k/2] != 0) { - assert(memcmp(buffer+i, buffer+j, k) < 0); - } else { - assert(memcmp(buffer+i, buffer+j, k) > 0); - } - } - } - } - return 0; + buffer[i + k / 2]--; + buffer[j + k / 2]++; + if (buffer[j + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) < 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) > 0); } -
\ No newline at end of file + } + } + } + return 0; +} diff --git a/tests/core/test_memmove.in b/tests/core/test_memmove.in index 690075d9..615a5ae1 100644 --- a/tests/core/test_memmove.in +++ b/tests/core/test_memmove.in @@ -1,10 +1,8 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char str[] = "memmove can be very useful....!"; - memmove (str+20, str+15, 11); - puts(str); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char str[] = "memmove can be very useful....!"; + memmove(str + 20, str + 15, 11); + puts(str); + return 0; +} diff --git a/tests/core/test_memmove2.in b/tests/core/test_memmove2.in index 087f59b8..2aed0b51 100644 --- a/tests/core/test_memmove2.in +++ b/tests/core/test_memmove2.in @@ -1,24 +1,22 @@ - - #include <stdio.h> - #include <string.h> - #include <assert.h> - int main() { - int sum = 0; - char buffer[256]; - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - for (int k = 0; k < 35; k++) { - for (int t = 0; t < 256; t++) buffer[t] = t; - char *dest = buffer + i; - char *src = buffer + j; - if (dest == src) continue; - //printf("%d, %d, %d\n", i, j, k); - assert(memmove(dest, src, k) == dest); - for (int t = 0; t < 256; t++) sum += buffer[t]; - } - } - } - printf("final: %d.\n", sum); - return 1; +#include <stdio.h> +#include <string.h> +#include <assert.h> +int main() { + int sum = 0; + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i; + char *src = buffer + j; + if (dest == src) continue; + // printf("%d, %d, %d\n", i, j, k); + assert(memmove(dest, src, k) == dest); + for (int t = 0; t < 256; t++) sum += buffer[t]; } -
\ No newline at end of file + } + } + printf("final: %d.\n", sum); + return 1; +} diff --git a/tests/core/test_memmove3.in b/tests/core/test_memmove3.in index a28267cd..27f9055b 100644 --- a/tests/core/test_memmove3.in +++ b/tests/core/test_memmove3.in @@ -1,10 +1,8 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char str[] = "memmove can be vvery useful....!"; - memmove(str+15, str+16, 17); - puts(str); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char str[] = "memmove can be vvery useful....!"; + memmove(str + 15, str + 16, 17); + puts(str); + return 0; +} diff --git a/tests/core/test_mmap.in b/tests/core/test_mmap.in index 46400278..16c1c647 100644 --- a/tests/core/test_mmap.in +++ b/tests/core/test_mmap.in @@ -1,38 +1,36 @@ - - #include <stdio.h> - #include <sys/mman.h> - #include <assert.h> - - int main(int argc, char *argv[]) { - for (int i = 0; i < 10; i++) { - int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - /* TODO: Should we align to 4k? - assert(((int)map) % 4096 == 0); // aligned - */ - assert(munmap(map, 5000) == 0); - } - - const int NUM_BYTES = 8 * 1024 * 1024; - const int NUM_INTS = NUM_BYTES / sizeof(int); - - int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - assert(map != MAP_FAILED); - - int i; - - for (i = 0; i < NUM_INTS; i++) { - map[i] = i; - } - - for (i = 0; i < NUM_INTS; i++) { - assert(map[i] == i); - } - - assert(munmap(map, NUM_BYTES) == 0); - - printf("hello,world"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <sys/mman.h> +#include <assert.h> + +int main(int argc, char* argv[]) { + for (int i = 0; i < 10; i++) { + int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + /* TODO: Should we align to 4k? + assert(((int)map) % 4096 == 0); // aligned + */ + assert(munmap(map, 5000) == 0); + } + + const int NUM_BYTES = 8 * 1024 * 1024; + const int NUM_INTS = NUM_BYTES / sizeof(int); + + int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + assert(map != MAP_FAILED); + + int i; + + for (i = 0; i < NUM_INTS; i++) { + map[i] = i; + } + + for (i = 0; i < NUM_INTS; i++) { + assert(map[i] == i); + } + + assert(munmap(map, NUM_BYTES) == 0); + + printf("hello,world"); + return 0; +} diff --git a/tests/core/test_mod_globalstruct.in b/tests/core/test_mod_globalstruct.in index 3e1ed493..3a8522cc 100644 --- a/tests/core/test_mod_globalstruct.in +++ b/tests/core/test_mod_globalstruct.in @@ -1,19 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +struct malloc_params { + size_t magic, page_size; +}; - struct malloc_params { - size_t magic, page_size; - }; +malloc_params mparams; - malloc_params mparams; +#define SIZE_T_ONE ((size_t)1) +#define page_align(S) \ + (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) - #define SIZE_T_ONE ((size_t)1) - #define page_align(S) (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) - - int main() - { - mparams.page_size = 4096; - printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), page_align(6000), page_align(66474)); - return 0; - } -
\ No newline at end of file +int main() { + mparams.page_size = 4096; + printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), + page_align(6000), page_align(66474)); + return 0; +} diff --git a/tests/core/test_multiexception.in b/tests/core/test_multiexception.in index 93795388..46acbbf3 100644 --- a/tests/core/test_multiexception.in +++ b/tests/core/test_multiexception.in @@ -1,48 +1,50 @@ - #include <stdio.h> static int current_exception_id = 0; typedef struct { -int jmp; + int jmp; } jmp_state; void setjmp_func(jmp_state* s, int level) { -int prev_jmp = s->jmp; -int c_jmp; + int prev_jmp = s->jmp; + int c_jmp; -if (level == 2) { - printf("level is 2, perform longjmp!\n"); - throw 1; -} + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + throw 1; + } -c_jmp = current_exception_id++; -try { - printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - s->jmp = c_jmp; - setjmp_func(s, level + 1); -} catch (int catched_eid) { - printf("caught %d\n", catched_eid); - if (catched_eid == c_jmp) { - printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - if (prev_jmp != -1) { - printf("prev_jmp is not empty, continue with longjmp!\n"); - s->jmp = prev_jmp; - throw s->jmp; + c_jmp = current_exception_id++; + try { + printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, + prev_jmp); + s->jmp = c_jmp; + setjmp_func(s, level + 1); + } + catch (int catched_eid) { + printf("caught %d\n", catched_eid); + if (catched_eid == c_jmp) { + printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", + level, prev_jmp); + if (prev_jmp != -1) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + throw s->jmp; + } + } else { + throw; } - } else { - throw; } -} -printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); + printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); } -int main(int argc, char *argv[]) { -jmp_state s; -s.jmp = -1; +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = -1; -setjmp_func(&s, 0); + setjmp_func(&s, 0); -return 0; + return 0; } diff --git a/tests/core/test_negative_zero.in b/tests/core/test_negative_zero.in index 8e1fcc0b..395f84ce 100644 --- a/tests/core/test_negative_zero.in +++ b/tests/core/test_negative_zero.in @@ -1,30 +1,27 @@ +#include <stdio.h> +#include <math.h> - #include <stdio.h> - #include <math.h> - - int main() { - #define TEST(x, y) \ - printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); - TEST( 5.0f, 5.0f); - TEST( 5.0f, -5.0f); - TEST(-5.0f, 5.0f); - TEST(-5.0f, -5.0f); - TEST( 5.0f, 4.0f); - TEST( 5.0f, -4.0f); - TEST(-5.0f, 4.0f); - TEST(-5.0f, -4.0f); - TEST( 0.0f, 5.0f); - TEST( 0.0f, -5.0f); - TEST(-0.0f, 5.0f); - TEST(-0.0f, -5.0f); - TEST( 5.0f, 0.0f); - TEST( 5.0f, -0.0f); - TEST(-5.0f, 0.0f); - TEST(-5.0f, -0.0f); - TEST( 0.0f, 0.0f); - TEST( 0.0f, -0.0f); - TEST(-0.0f, 0.0f); - TEST(-0.0f, -0.0f); - return 0; - } -
\ No newline at end of file +int main() { +#define TEST(x, y) printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); + TEST(5.0f, 5.0f); + TEST(5.0f, -5.0f); + TEST(-5.0f, 5.0f); + TEST(-5.0f, -5.0f); + TEST(5.0f, 4.0f); + TEST(5.0f, -4.0f); + TEST(-5.0f, 4.0f); + TEST(-5.0f, -4.0f); + TEST(0.0f, 5.0f); + TEST(0.0f, -5.0f); + TEST(-0.0f, 5.0f); + TEST(-0.0f, -5.0f); + TEST(5.0f, 0.0f); + TEST(5.0f, -0.0f); + TEST(-5.0f, 0.0f); + TEST(-5.0f, -0.0f); + TEST(0.0f, 0.0f); + TEST(0.0f, -0.0f); + TEST(-0.0f, 0.0f); + TEST(-0.0f, -0.0f); + return 0; +} diff --git a/tests/core/test_perrar.in b/tests/core/test_perrar.in index e15c583a..d7c9eae7 100644 --- a/tests/core/test_perrar.in +++ b/tests/core/test_perrar.in @@ -1,13 +1,10 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> - #include <sys/types.h> - #include <sys/stat.h> - #include <fcntl.h> - #include <stdio.h> - - int main( int argc, char** argv ){ - int retval = open( "NonExistingFile", O_RDONLY ); - if( retval == -1 ) - perror( "Cannot open NonExistingFile" ); - return 0; - } -
\ No newline at end of file +int main(int argc, char** argv) { + int retval = open("NonExistingFile", O_RDONLY); + if (retval == -1) perror("Cannot open NonExistingFile"); + return 0; +} diff --git a/tests/core/test_phiundef.in b/tests/core/test_phiundef.in index cf4b0f18..91273cc9 100644 --- a/tests/core/test_phiundef.in +++ b/tests/core/test_phiundef.in @@ -1,18 +1,17 @@ - #include <stdlib.h> #include <stdio.h> static int state; struct my_struct { -union { - struct { - unsigned char a; - unsigned char b; - } c; - unsigned int d; -} e; -unsigned int f; + union { + struct { + unsigned char a; + unsigned char b; + } c; + unsigned int d; + } e; + unsigned int f; }; int main(int argc, char **argv) { @@ -20,14 +19,12 @@ int main(int argc, char **argv) { state = 0; - for (int i=0;i<argc+10;i++) - { - if (state % 2 == 0) - r.e.c.a = 3; - else - printf("%d\n", r.e.c.a); - state++; + for (int i = 0; i < argc + 10; i++) { + if (state % 2 == 0) + r.e.c.a = 3; + else + printf("%d\n", r.e.c.a); + state++; } return 0; } -
\ No newline at end of file diff --git a/tests/core/test_poll.in b/tests/core/test_poll.in index 3fb0ebc9..aa2c09ee 100644 --- a/tests/core/test_poll.in +++ b/tests/core/test_poll.in @@ -1,30 +1,28 @@ +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <poll.h> - #include <stdio.h> - #include <errno.h> - #include <fcntl.h> - #include <poll.h> +int main() { + struct pollfd multi[5]; + multi[0].fd = open("/file", O_RDONLY, 0777); + multi[1].fd = open("/device", O_RDONLY, 0777); + multi[2].fd = 123; + multi[3].fd = open("/file", O_RDONLY, 0777); + multi[4].fd = open("/file", O_RDONLY, 0777); + multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[3].events = 0x00; + multi[4].events = POLLOUT | POLLNVAL | POLLERR; - int main() { - struct pollfd multi[5]; - multi[0].fd = open("/file", O_RDONLY, 0777); - multi[1].fd = open("/device", O_RDONLY, 0777); - multi[2].fd = 123; - multi[3].fd = open("/file", O_RDONLY, 0777); - multi[4].fd = open("/file", O_RDONLY, 0777); - multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[3].events = 0x00; - multi[4].events = POLLOUT | POLLNVAL | POLLERR; + printf("ret: %d\n", poll(multi, 5, 123)); + printf("errno: %d\n", errno); + printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT)); + printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT)); + printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL); + printf("multi[3].revents: %d\n", multi[3].revents == 0); + printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT); - printf("ret: %d\n", poll(multi, 5, 123)); - printf("errno: %d\n", errno); - printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT)); - printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT)); - printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL); - printf("multi[3].revents: %d\n", multi[3].revents == 0); - printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_polymorph.in b/tests/core/test_polymorph.in index 2faa1935..1f24a1aa 100644 --- a/tests/core/test_polymorph.in +++ b/tests/core/test_polymorph.in @@ -1,34 +1,33 @@ +#include <stdio.h> +struct Pure { + virtual int implme() = 0; +}; +struct Parent : Pure { + virtual int getit() { + return 11; + }; + int implme() { return 32; } +}; +struct Child : Parent { + int getit() { return 74; } + int implme() { return 1012; } +}; - #include <stdio.h> - struct Pure { - virtual int implme() = 0; - }; - struct Parent : Pure { - virtual int getit() { return 11; }; - int implme() { return 32; } - }; - struct Child : Parent { - int getit() { return 74; } - int implme() { return 1012; } - }; +struct Other { + int one() { return 11; } + int two() { return 22; } +}; - struct Other { - int one() { return 11; } - int two() { return 22; } - }; +int main() { + Parent *x = new Parent(); + Parent *y = new Child(); + printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme()); - int main() - { - Parent *x = new Parent(); - Parent *y = new Child(); - printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme()); + Other *o = new Other; + int (Other::*Ls)() = &Other::one; + printf("*%d*\n", (o->*(Ls))()); + Ls = &Other::two; + printf("*%d*\n", (o->*(Ls))()); - Other *o = new Other; - int (Other::*Ls)() = &Other::one; - printf("*%d*\n", (o->*(Ls))()); - Ls = &Other::two; - printf("*%d*\n", (o->*(Ls))()); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_printf_2.in b/tests/core/test_printf_2.in index ef94aec1..8fb16173 100644 --- a/tests/core/test_printf_2.in +++ b/tests/core/test_printf_2.in @@ -1,17 +1,15 @@ +#include <stdio.h> - #include <stdio.h> +int main() { + char c = '1'; + short s = 2; + int i = 3; + long long l = 4; + float f = 5.5; + double d = 6.6; - int main() { - char c = '1'; - short s = 2; - int i = 3; - long long l = 4; - float f = 5.5; - double d = 6.6; + printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d); + printf("%#x,%#x\n", 1, 0); - printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d); - printf("%#x,%#x\n", 1, 0); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_printf_more.in b/tests/core/test_printf_more.in index b8e3ba61..ad1cebc8 100644 --- a/tests/core/test_printf_more.in +++ b/tests/core/test_printf_more.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - int main() { - int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345); - char buf[size]; - snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345); - printf("%d : %s\n", size, buf); - char *buff = NULL; - asprintf(&buff, "%d waka %d\n", 21, 95); - puts(buff); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345); + char buf[size]; + snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345); + printf("%d : %s\n", size, buf); + char *buff = NULL; + asprintf(&buff, "%d waka %d\n", 21, 95); + puts(buff); + return 0; +} diff --git a/tests/core/test_ptrtoint.in b/tests/core/test_ptrtoint.in index be7214e8..88e91262 100644 --- a/tests/core/test_ptrtoint.in +++ b/tests/core/test_ptrtoint.in @@ -1,16 +1,14 @@ +#include <stdio.h> - #include <stdio.h> - - int main( int argc, const char *argv[] ) { - char *a = new char[10]; - char *a0 = a+0; - char *a5 = a+5; - int *b = new int[10]; - int *b0 = b+0; - int *b5 = b+5; - int c = (int)b5-(int)b0; // Emscripten should warn! - int d = (int)b5-(int)b0; // Emscripten should warn! - printf("*%d*\n", (int)a5-(int)a0); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + char *a = new char[10]; + char *a0 = a + 0; + char *a5 = a + 5; + int *b = new int[10]; + int *b0 = b + 0; + int *b5 = b + 5; + int c = (int)b5 - (int)b0; // Emscripten should warn! + int d = (int)b5 - (int)b0; // Emscripten should warn! + printf("*%d*\n", (int)a5 - (int)a0); + return 0; +} diff --git a/tests/core/test_regex.in b/tests/core/test_regex.in index a7ceb7a3..4f1bdd21 100644 --- a/tests/core/test_regex.in +++ b/tests/core/test_regex.in @@ -1,37 +1,36 @@ -// This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm - #include <regex.h> - #include <stdio.h> - #include <stdlib.h> +// This is from// http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> - int main(void) - { - regex_t preg; - const char *string = "a very simple simple simple string"; - const char *pattern = "\\(sim[a-z]le\\) \\1"; - int rc; - size_t nmatch = 2; - regmatch_t pmatch[2]; +int main(void) { + regex_t preg; + const char *string = "a very simple simple simple string"; + const char *pattern = "\\(sim[a-z]le\\) \\1"; + int rc; + size_t nmatch = 2; + regmatch_t pmatch[2]; - if (0 != (rc = regcomp(&preg, pattern, 0))) { - printf("regcomp() failed, returning nonzero (%d)\n", rc); - exit(EXIT_FAILURE); - } + if (0 != (rc = regcomp(&preg, pattern, 0))) { + printf("regcomp() failed, returning nonzero (%d)\n", rc); + exit(EXIT_FAILURE); + } - if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { - printf("Failed to match '%s' with '%s',returning %d.\n", - string, pattern, rc); - } - else { - printf("With the whole expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], - pmatch[0].rm_so, pmatch[0].rm_eo - 1); - printf("With the sub-expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], - pmatch[1].rm_so, pmatch[1].rm_eo - 1); - } - regfree(&preg); - return 0; - } - + if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { + printf("Failed to match '%s' with '%s',returning %d.\n", string, pattern, + rc); + } else { + printf( + "With the whole expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], + pmatch[0].rm_so, pmatch[0].rm_eo - 1); + printf( + "With the sub-expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], + pmatch[1].rm_so, pmatch[1].rm_eo - 1); + } + regfree(&preg); + return 0; +} diff --git a/tests/core/test_reinterpreted_ptrs.in b/tests/core/test_reinterpreted_ptrs.in index e5e257e0..9865c61f 100644 --- a/tests/core/test_reinterpreted_ptrs.in +++ b/tests/core/test_reinterpreted_ptrs.in @@ -1,13 +1,13 @@ - #include <stdio.h> class Foo { -private: + private: float bar; -public: + + public: int baz; - Foo(): bar(0), baz(4711) {}; + Foo() : bar(0), baz(4711) {}; int getBar() const; }; @@ -16,8 +16,8 @@ int Foo::getBar() const { return this->bar; }; -const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F); -const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F); +const Foo *magic1 = reinterpret_cast<Foo *>(0xDEAD111F); +const Foo *magic2 = reinterpret_cast<Foo *>(0xDEAD888F); static void runTest() { @@ -25,17 +25,16 @@ static void runTest() { const Foo *b = a; if (a->getBar() == 0) { - if (a->baz == 4712) - b = magic1; - else - b = magic2; + if (a->baz == 4712) + b = magic1; + else + b = magic2; } - printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); + printf("%s\n", + (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); }; extern "C" { - int main(int argc, char **argv) { - runTest(); - } +int main(int argc, char **argv) { runTest(); } } diff --git a/tests/core/test_rounding.in b/tests/core/test_rounding.in index 63960ac4..af7d9099 100644 --- a/tests/core/test_rounding.in +++ b/tests/core/test_rounding.in @@ -1,29 +1,26 @@ +#include <stdio.h> +#include <math.h> - #include <stdio.h> - #include <math.h> +int main() { + printf("%.1f ", round(1.4)); + printf("%.1f ", round(1.6)); + printf("%.1f ", round(-1.4)); + printf("%.1f ", round(-1.6)); - int main() - { - printf("%.1f ", round(1.4)); - printf("%.1f ", round(1.6)); - printf("%.1f ", round(-1.4)); - printf("%.1f ", round(-1.6)); + printf("%.1f ", round(1.5)); + printf("%.1f ", round(2.5)); + printf("%.1f ", round(-1.5)); + printf("%.1f ", round(-2.5)); - printf("%.1f ", round(1.5)); - printf("%.1f ", round(2.5)); - printf("%.1f ", round(-1.5)); - printf("%.1f ", round(-2.5)); + printf("%ld ", lrint(1.4)); + printf("%ld ", lrint(1.6)); + printf("%ld ", lrint(-1.4)); + printf("%ld ", lrint(-1.6)); - printf("%ld ", lrint(1.4)); - printf("%ld ", lrint(1.6)); - printf("%ld ", lrint(-1.4)); - printf("%ld ", lrint(-1.6)); + printf("%ld ", lrint(1.5)); + printf("%ld ", lrint(2.5)); + printf("%ld ", lrint(-1.5)); + printf("%ld ", lrint(-2.5)); - printf("%ld ", lrint(1.5)); - printf("%ld ", lrint(2.5)); - printf("%ld ", lrint(-1.5)); - printf("%ld ", lrint(-2.5)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_simd.in b/tests/core/test_simd.in index 978ea96a..5018b8e3 100644 --- a/tests/core/test_simd.in +++ b/tests/core/test_simd.in @@ -1,61 +1,69 @@ - #include <stdio.h> #include <emscripten/vector.h> static inline float32x4 __attribute__((always_inline)) -_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) -{ - return (float32x4){ __W, __X, __Y, __Z }; + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (float32x4) {__W, __X, __Y, __Z}; } static __inline__ float32x4 __attribute__((__always_inline__)) -_mm_setzero_ps(void) -{ - return (float32x4){ 0.0, 0.0, 0.0, 0.0 }; + _mm_setzero_ps(void) { + return (float32x4) {0.0, 0.0, 0.0, 0.0}; } int main(int argc, char **argv) { float data[8]; - for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer + for (int i = 0; i < 32; i++) + data[i] = (1 + i + argc) * (2 + i + argc * argc); // confuse optimizer { - float32x4 *a = (float32x4*)&data[0]; - float32x4 *b = (float32x4*)&data[4]; + float32x4 *a = (float32x4 *)&data[0]; + float32x4 *b = (float32x4 *)&data[4]; float32x4 c, d; c = *a; d = *b; - printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - c = c+d; - printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - d = c*d; - printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = c + d; + printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + d = c * d; + printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); c = _mm_setzero_ps(); - printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]); + printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], + (int)c[3]); } { - int32x4 *a = (int32x4*)&data[0]; - int32x4 *b = (int32x4*)&data[4]; + int32x4 *a = (int32x4 *)&data[0]; + int32x4 *b = (int32x4 *)&data[4]; int32x4 c, d, e, f; c = *a; d = *b; - printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]); - e = c+d; - f = c-d; - printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); - e = c&d; - f = c|d; - e = ~c&d; - f = c^d; - printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); + printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], + d[0], d[1], d[2], d[3]); + e = c + d; + f = c - d; + printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); + e = c & d; + f = c | d; + e = ~c & d; + f = c ^ d; + printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); } { float32x4 c, d, e, f; c = _mm_set_ps(9.0, 4.0, 0, -9.0); d = _mm_set_ps(10.0, 14.0, -12, -2.0); - printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well + printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + printf("7calcs: %d\n", + emscripten_float32x4_signmask(c)); // TODO: just not just + // compilation but output as well } return 0; } -
\ No newline at end of file diff --git a/tests/core/test_simd2.in b/tests/core/test_simd2.in index 97b1d841..be1655c2 100644 --- a/tests/core/test_simd2.in +++ b/tests/core/test_simd2.in @@ -1,39 +1,35 @@ +#include <stdio.h> - #include <stdio.h> - - typedef float __m128 __attribute__ ((__vector_size__ (16))); - - static inline __m128 __attribute__((always_inline)) - _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) - { - return (__m128){ __W, __X, __Y, __Z }; - } - - static inline void __attribute__((always_inline)) - _mm_store_ps(float *__P, __m128 __A) - { - *(__m128 *)__P = __A; - } - - static inline __m128 __attribute__((always_inline)) - _mm_add_ps(__m128 __A, __m128 __B) - { - return __A + __B; - } - - using namespace std; - - int main(int argc, char ** argv) { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); - __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); - __m128 v3 = _mm_add_ps(v1, v2); - _mm_store_ps(ar, v3); - - for (int i = 0; i < 4; i++) { - printf("%f\n", ar[i]); - } - - return 0; - } -
\ No newline at end of file +typedef float __m128 __attribute__((__vector_size__(16))); + +static inline __m128 __attribute__((always_inline)) + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (__m128) {__W, __X, __Y, __Z}; +} + +static inline void __attribute__((always_inline)) + _mm_store_ps(float *__P, __m128 __A) { + *(__m128 *)__P = __A; +} + +static inline __m128 __attribute__((always_inline)) + _mm_add_ps(__m128 __A, __m128 __B) { + return __A + __B; +} + +using namespace std; + +int main(int argc, char **argv) { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); + __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); + __m128 v3 = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v3); + + for (int i = 0; i < 4; i++) { + printf("%f\n", ar[i]); + } + + return 0; +} diff --git a/tests/core/test_simd3.in b/tests/core/test_simd3.in index 462370e7..f005d847 100644 --- a/tests/core/test_simd3.in +++ b/tests/core/test_simd3.in @@ -1,471 +1,488 @@ - - #include <iostream> - #include <emmintrin.h> - #include <assert.h> - #include <stdint.h> - #include <bitset> - - using namespace std; - - void testSetPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0); - _mm_store_ps(ar, v); - assert(ar[0] == 4.0); - assert(ar[1] == 3.0); - assert(ar[2] == 2.0); - assert(ar[3] == 1.0); - } - - void testSet1Ps() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_set1_ps(5.5); - _mm_store_ps(ar, v); - assert(ar[0] == 5.5); - assert(ar[1] == 5.5); - assert(ar[2] == 5.5); - assert(ar[3] == 5.5); - } - - void testSetZeroPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_setzero_ps(); - _mm_store_ps(ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testSetEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_set_epi32(5, 7, 126, 381); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 381); - assert(ar[1] == 126); - assert(ar[2] == 7); - assert(ar[3] == 5); - v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x12345678); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xaaaaaaaa); - assert(ar[3] == 0x55555555); - } - - void testSet1Epi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_set1_epi32(-5); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == -5); - assert(ar[1] == -5); - assert(ar[2] == -5); - assert(ar[3] == -5); - } - - void testSetZeroSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_setzero_si128(); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testBitCasts() { - int32_t __attribute__((__aligned__(16))) ar1[4]; - float __attribute__((__aligned__(16))) ar2[4]; - __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000); - __m128 v2 = _mm_castsi128_ps(v1); - _mm_store_ps(ar2, v2); - assert(ar2[0] == 4.0); - assert(ar2[1] == 3.0); - assert(ar2[2] == 2.0); - assert(ar2[3] == 1.0); - v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0); - v1 = _mm_castps_si128(v2); - _mm_store_si128((__m128i *)ar1, v1); - assert(ar1[0] == 0x41000000); - assert(ar1[1] == 0x40e00000); - assert(ar1[2] == 0x40c00000); - assert(ar1[3] == 0x40a00000); - float w = 0; - float z = -278.3; - float y = 5.2; - float x = -987654321; - v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x)); - _mm_store_ps(ar2, _mm_castsi128_ps(v1)); - assert(ar2[0] == x); - assert(ar2[1] == y); - assert(ar2[2] == z); - assert(ar2[3] == w); - /* - std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned long*>(&(ar2[0]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned long*>(&(ar2[1]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned long*>(&(ar2[2]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned long*>(&(ar2[3]))); - std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned long*>(&x)); - std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned long*>(&y)); - std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned long*>(&z)); - std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned long*>(&w)); - assert(bits1x == bits2x); - assert(bits1y == bits2y); - assert(bits1z == bits2z); - assert(bits1w == bits2w); - */ - v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa)); - _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2)); - assert(ar1[0] == 0xaaaaaaaa); - assert(ar1[1] == 0x5555cccc); - assert(ar1[2] == 0); - assert(ar1[3] == 0xffffffff); - } - - void testConversions() { - int32_t __attribute__((__aligned__(16))) ar1[4]; - float __attribute__((__aligned__(16))) ar2[4]; - __m128i v1 = _mm_set_epi32(0, -3, -517, 256); - __m128 v2 = _mm_cvtepi32_ps(v1); - _mm_store_ps(ar2, v2); - assert(ar2[0] == 256.0); - assert(ar2[1] == -517.0); - assert(ar2[2] == -3.0); - assert(ar2[3] == 0); - v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0); - v1 = _mm_cvtps_epi32(v2); - _mm_store_si128((__m128i *)ar1, v1); - assert(ar1[0] == -8); - assert(ar1[1] == 7); - assert(ar1[2] == 6); - assert(ar1[3] == 5); - } - - void testMoveMaskPs() { - __m128 v = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - int mask = _mm_movemask_ps(v); - assert(mask == 13); - } - - void testAddPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_add_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 41.0); - assert(ar[1] == 32.0); - assert(ar[2] == 23.0); - assert(ar[3] == 14.0); - } - - void testSubPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_sub_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == -39.0); - assert(ar[1] == -28.0); - assert(ar[2] == -17.0); - assert(ar[3] == -6.0); - } - - void testMulPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_mul_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 40.0); - assert(ar[1] == 60.0); - assert(ar[2] == 60.0); - assert(ar[3] == 40.0); - } - - void testDivPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0); - __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5); - __m128 v = _mm_div_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 2.0); - assert(ar[1] == 8.0); - assert(ar[2] == 3.0); - assert(ar[3] == 2.0); - } - - void testMinPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); - __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0); - __m128 v = _mm_min_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 0.0); - assert(ar[1] == 30.0); - assert(ar[2] == 1.0); - assert(ar[3] == -20.0); - } - - void testMaxPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); - __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0); - __m128 v = _mm_max_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 1.0); - assert(ar[1] == 55.0); - assert(ar[2] == 10.0); - assert(ar[3] == 2.5); - } - - void testSqrtPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0); - __m128 v = _mm_sqrt_ps(v1); - _mm_store_ps(ar, v); - assert(ar[0] == 1.0); - assert(ar[1] == 2.0); - assert(ar[2] == 3.0); - assert(ar[3] == 4.0); - } - - void testCmpLtPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmplt_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0xffffffff); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0xffffffff); - assert(_mm_movemask_ps(v) == 9); - } - - void testCmpLePs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmple_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0xffffffff); - assert(ar[1] == 0); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - assert(_mm_movemask_ps(v) == 13); - } - - void testCmpEqPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpeq_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 4); - } - - void testCmpGePs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpge_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 6); - } - - void testCmpGtPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpgt_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 2); - } - - void testAndPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(425, -501, -32, 68); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - __m128 v = _mm_and_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 68); - assert(ar[1] == 0); - assert(ar[2] == -501); - assert(ar[3] == 425); - int32_t __attribute__((__aligned__(16))) ar2[4]; - v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); - v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - v = _mm_and_ps(v1, v2); - _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); - assert(ar2[0] == 0); - assert(ar2[1] == 0); - assert(ar2[2] == 0); - assert(ar2[3] == 0); - } - - void testAndNotPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(425, -501, -32, 68); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - __m128 v = _mm_andnot_ps(v2, v1); - _mm_store_ps(ar, v); - assert(ar[0] == 0); - assert(ar[1] == -32); - assert(ar[2] == 0); - assert(ar[3] == 0); - int32_t __attribute__((__aligned__(16))) ar2[4]; - v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); - v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - v = _mm_andnot_ps(v1, v2); - _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); - assert(ar2[0] == 0x55555555); - assert(ar2[1] == 0x55555555); - assert(ar2[2] == 0x55555555); - assert(ar2[3] == 0x55555555); - } - - void testOrPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - __m128 v = _mm_or_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testXorPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - __m128 v = _mm_xor_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xaaaaaaaa); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testAndSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_and_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testAndNotSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_andnot_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0x55555555); - assert(ar[2] == 0x55555555); - assert(ar[3] == 0x55555555); - } - - void testOrSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_or_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testXorSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_xor_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xaaaaaaaa); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testAddEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(4, 3, 2, 1); - __m128i v2 = _mm_set_epi32(10, 20, 30, 40); - __m128i v = _mm_add_epi32(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 41); - assert(ar[1] == 32); - assert(ar[2] == 23); - assert(ar[3] == 14); - } - - void testSubEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(4, 3, 2, 1); - __m128i v2 = _mm_set_epi32(10, 20, 30, 40); - __m128i v = _mm_sub_epi32(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == -39); - assert(ar[1] == -28); - assert(ar[2] == -17); - assert(ar[3] == -6); - } - - int main(int argc, char ** argv) { - testSetPs(); - testSet1Ps(); - testSetZeroPs(); - testSetEpi32(); - testSet1Epi32(); - testSetZeroSi128(); - testBitCasts(); - testConversions(); - testMoveMaskPs(); - testAddPs(); - testSubPs(); - testMulPs(); - testDivPs(); - testMaxPs(); - testMinPs(); - testSqrtPs(); - testCmpLtPs(); - testCmpLePs(); - testCmpEqPs(); - testCmpGePs(); - testCmpGtPs(); - testAndPs(); - testAndNotPs(); - testOrPs(); - testXorPs(); - testAndSi128(); - testAndNotSi128(); - testOrSi128(); - testXorSi128(); - testAddEpi32(); - testSubEpi32(); - printf("DONE"); - return 0; - } -
\ No newline at end of file +#include <iostream> +#include <emmintrin.h> +#include <assert.h> +#include <stdint.h> +#include <bitset> + +using namespace std; + +void testSetPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0); + _mm_store_ps(ar, v); + assert(ar[0] == 4.0); + assert(ar[1] == 3.0); + assert(ar[2] == 2.0); + assert(ar[3] == 1.0); +} + +void testSet1Ps() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set1_ps(5.5); + _mm_store_ps(ar, v); + assert(ar[0] == 5.5); + assert(ar[1] == 5.5); + assert(ar[2] == 5.5); + assert(ar[3] == 5.5); +} + +void testSetZeroPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_setzero_ps(); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testSetEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set_epi32(5, 7, 126, 381); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 381); + assert(ar[1] == 126); + assert(ar[2] == 7); + assert(ar[3] == 5); + v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x12345678); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xaaaaaaaa); + assert(ar[3] == 0x55555555); +} + +void testSet1Epi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set1_epi32(-5); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -5); + assert(ar[1] == -5); + assert(ar[2] == -5); + assert(ar[3] == -5); +} + +void testSetZeroSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_setzero_si128(); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testBitCasts() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000); + __m128 v2 = _mm_castsi128_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 4.0); + assert(ar2[1] == 3.0); + assert(ar2[2] == 2.0); + assert(ar2[3] == 1.0); + v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0); + v1 = _mm_castps_si128(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == 0x41000000); + assert(ar1[1] == 0x40e00000); + assert(ar1[2] == 0x40c00000); + assert(ar1[3] == 0x40a00000); + float w = 0; + float z = -278.3; + float y = 5.2; + float x = -987654321; + v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x)); + _mm_store_ps(ar2, _mm_castsi128_ps(v1)); + assert(ar2[0] == x); + assert(ar2[1] == y); + assert(ar2[2] == z); + assert(ar2[3] == w); + /* + std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned + long*>(&(ar2[0]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned + long*>(&(ar2[1]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned + long*>(&(ar2[2]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned + long*>(&(ar2[3]))); + std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned + long*>(&x)); + std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned + long*>(&y)); + std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned + long*>(&z)); + std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned + long*>(&w)); + assert(bits1x == bits2x); + assert(bits1y == bits2y); + assert(bits1z == bits2z); + assert(bits1w == bits2w); + */ + v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa)); + _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2)); + assert(ar1[0] == 0xaaaaaaaa); + assert(ar1[1] == 0x5555cccc); + assert(ar1[2] == 0); + assert(ar1[3] == 0xffffffff); +} + +void testConversions() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0, -3, -517, 256); + __m128 v2 = _mm_cvtepi32_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 256.0); + assert(ar2[1] == -517.0); + assert(ar2[2] == -3.0); + assert(ar2[3] == 0); + v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0); + v1 = _mm_cvtps_epi32(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == -8); + assert(ar1[1] == 7); + assert(ar1[2] == 6); + assert(ar1[3] == 5); +} + +void testMoveMaskPs() { + __m128 v = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + int mask = _mm_movemask_ps(v); + assert(mask == 13); +} + +void testAddPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 41.0); + assert(ar[1] == 32.0); + assert(ar[2] == 23.0); + assert(ar[3] == 14.0); +} + +void testSubPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_sub_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == -39.0); + assert(ar[1] == -28.0); + assert(ar[2] == -17.0); + assert(ar[3] == -6.0); +} + +void testMulPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_mul_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 40.0); + assert(ar[1] == 60.0); + assert(ar[2] == 60.0); + assert(ar[3] == 40.0); +} + +void testDivPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0); + __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5); + __m128 v = _mm_div_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 2.0); + assert(ar[1] == 8.0); + assert(ar[2] == 3.0); + assert(ar[3] == 2.0); +} + +void testMinPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0); + __m128 v = _mm_min_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 0.0); + assert(ar[1] == 30.0); + assert(ar[2] == 1.0); + assert(ar[3] == -20.0); +} + +void testMaxPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0); + __m128 v = _mm_max_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 55.0); + assert(ar[2] == 10.0); + assert(ar[3] == 2.5); +} + +void testSqrtPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0); + __m128 v = _mm_sqrt_ps(v1); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 2.0); + assert(ar[2] == 3.0); + assert(ar[3] == 4.0); +} + +void testCmpLtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmplt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 9); +} + +void testCmpLePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmple_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 13); +} + +void testCmpEqPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpeq_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 4); +} + +void testCmpGePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpge_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 6); +} + +void testCmpGtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpgt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 2); +} + +void testAndPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_and_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 68); + assert(ar[1] == 0); + assert(ar[2] == -501); + assert(ar[3] == 425); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_and_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0); + assert(ar2[1] == 0); + assert(ar2[2] == 0); + assert(ar2[3] == 0); +} + +void testAndNotPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_andnot_ps(v2, v1); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == -32); + assert(ar[2] == 0); + assert(ar[3] == 0); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_andnot_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0x55555555); + assert(ar2[1] == 0x55555555); + assert(ar2[2] == 0x55555555); + assert(ar2[3] == 0x55555555); +} + +void testOrPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_or_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_xor_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAndSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_and_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testAndNotSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_andnot_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0x55555555); + assert(ar[2] == 0x55555555); + assert(ar[3] == 0x55555555); +} + +void testOrSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_or_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_xor_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAddEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_add_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 41); + assert(ar[1] == 32); + assert(ar[2] == 23); + assert(ar[3] == 14); +} + +void testSubEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_sub_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -39); + assert(ar[1] == -28); + assert(ar[2] == -17); + assert(ar[3] == -6); +} + +int main(int argc, char **argv) { + testSetPs(); + testSet1Ps(); + testSetZeroPs(); + testSetEpi32(); + testSet1Epi32(); + testSetZeroSi128(); + testBitCasts(); + testConversions(); + testMoveMaskPs(); + testAddPs(); + testSubPs(); + testMulPs(); + testDivPs(); + testMaxPs(); + testMinPs(); + testSqrtPs(); + testCmpLtPs(); + testCmpLePs(); + testCmpEqPs(); + testCmpGePs(); + testCmpGtPs(); + testAndPs(); + testAndNotPs(); + testOrPs(); + testXorPs(); + testAndSi128(); + testAndNotSi128(); + testOrSi128(); + testXorSi128(); + testAddEpi32(); + testSubEpi32(); + printf("DONE"); + return 0; +} diff --git a/tests/core/test_sintvars.in b/tests/core/test_sintvars.in index 1b377c7c..570dba48 100644 --- a/tests/core/test_sintvars.in +++ b/tests/core/test_sintvars.in @@ -1,25 +1,24 @@ +#include <stdio.h> +struct S { + char *match_start; + char *strstart; +}; +int main() { + struct S _s; + struct S *s = &_s; + unsigned short int sh; - #include <stdio.h> - struct S { - char *match_start; - char *strstart; - }; - int main() - { - struct S _s; - struct S *s = &_s; - unsigned short int sh; + s->match_start = (char *)32522; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); - s->match_start = (char*)32522; - s->strstart = (char*)(32780); - printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start)); - sh = s->strstart - s->match_start; - printf("*%d,%d*\n", sh, sh>>7); - - s->match_start = (char*)32999; - s->strstart = (char*)(32780); - printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start)); - sh = s->strstart - s->match_start; - printf("*%d,%d*\n", sh, sh>>7); - } -
\ No newline at end of file + s->match_start = (char *)32999; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); +} diff --git a/tests/core/test_sizeof.in b/tests/core/test_sizeof.in index 952e900e..1186ce41 100644 --- a/tests/core/test_sizeof.in +++ b/tests/core/test_sizeof.in @@ -1,29 +1,28 @@ +#include <stdio.h> +#include <string.h> +#include "emscripten.h" - #include <stdio.h> - #include <string.h> - #include "emscripten.h" +struct A { + int x, y; +}; - struct A { int x, y; }; +int main(int argc, const char *argv[]) { + int *a = new int[10]; + int *b = new int[1]; + int *c = new int[10]; + for (int i = 0; i < 10; i++) a[i] = 2; + *b = 5; + for (int i = 0; i < 10; i++) c[i] = 8; + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + // Should overwrite a, but not touch b! + memcpy(a, c, 10 * sizeof(int)); + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); - int main( int argc, const char *argv[] ) { - int *a = new int[10]; - int *b = new int[1]; - int *c = new int[10]; - for (int i = 0; i < 10; i++) - a[i] = 2; - *b = 5; - for (int i = 0; i < 10; i++) - c[i] = 8; - printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); - // Should overwrite a, but not touch b! - memcpy(a, c, 10*sizeof(int)); - printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + // Part 2 + A as[3] = {{5, 12}, {6, 990}, {7, 2}}; + memcpy(&as[0], &as[2], sizeof(A)); - // Part 2 - A as[3] = { { 5, 12 }, { 6, 990 }, { 7, 2 } }; - memcpy(&as[0], &as[2], sizeof(A)); - - printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, as[2].y); - return 0; - } -
\ No newline at end of file + printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, + as[2].y); + return 0; +} diff --git a/tests/core/test_sscanf.in b/tests/core/test_sscanf.in index 821e0c86..d5289fe5 100644 --- a/tests/core/test_sscanf.in +++ b/tests/core/test_sscanf.in @@ -1,88 +1,91 @@ - - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - int main () { - #define CHECK(str) \ - { \ - char name[1000]; \ - memset(name, 0, 1000); \ - int prio = 99; \ - sscanf(str, "%s %d", name, &prio); \ - printf("%s : %d\n", name, prio); \ - } - CHECK("en-us 2"); - CHECK("en-r"); - CHECK("en 3"); - - printf("%f, %f\n", atof("1.234567"), atof("cheez")); - - char float_formats[] = "fegE"; - char format[] = "%_"; - for(int i = 0; i < 4; ++i) { - format[1] = float_formats[i]; - - float n = -1; - sscanf(" 2.8208", format, &n); - printf("%.4f\n", n); - - float a = -1; - sscanf("-3.03", format, &a); - printf("%.4f\n", a); - } - - char buffy[100]; - sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - - int numverts = -1; - printf("%d\n", sscanf(" numverts 1499\n", " numverts %d", &numverts)); // white space is the same, even if tab vs space - printf("%d\n", numverts); - - int index; - float u, v; - short start, count; - printf("%d\n", sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); - printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); - - int neg, neg2, neg3 = 0; - printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); - printf("%d,%u,%d\n", neg, neg2, neg3); - - { - int a = 0; - sscanf("1", "%i", &a); - printf("%i\n", a); - } - - char buf1[100], buf2[100], buf3[100], buf4[100]; - - int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4); - printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); - - numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main() { +#define CHECK(str) \ + { \ + char name[1000]; \ + memset(name, 0, 1000); \ + int prio = 99; \ + sscanf(str, "%s %d", name, &prio); \ + printf("%s : %d\n", name, prio); \ + } + CHECK("en-us 2"); + CHECK("en-r"); + CHECK("en 3"); + + printf("%f, %f\n", atof("1.234567"), atof("cheez")); + + char float_formats[] = "fegE"; + char format[] = "%_"; + for (int i = 0; i < 4; ++i) { + format[1] = float_formats[i]; + + float n = -1; + sscanf(" 2.8208", format, &n); + printf("%.4f\n", n); + + float a = -1; + sscanf("-3.03", format, &a); + printf("%.4f\n", a); + } + + char buffy[100]; + sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + + int numverts = -1; + printf("%d\n", + sscanf(" numverts 1499\n", " numverts %d", + &numverts)); // white space is the same, even if tab vs space + printf("%d\n", numverts); + + int index; + float u, v; + short start, count; + printf("%d\n", + sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", + " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); + printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); + + int neg, neg2, neg3 = 0; + printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); + printf("%d,%u,%d\n", neg, neg2, neg3); + + { + int a = 0; + sscanf("1", "%i", &a); + printf("%i\n", a); + } + + char buf1[100], buf2[100], buf3[100], buf4[100]; + + int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", + buf1, buf2, buf3, buf4); + printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); + + numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + return 0; +} diff --git a/tests/core/test_sscanf_3.in b/tests/core/test_sscanf_3.in index fb8949e7..e21897ed 100644 --- a/tests/core/test_sscanf_3.in +++ b/tests/core/test_sscanf_3.in @@ -1,17 +1,17 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main() { - int main(){ + int64_t s, m, l; + printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, + &m, &l)); + printf("%lld,%lld,%lld\n", s, m, l); - int64_t s, m, l; - printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, &m, &l)); - printf("%lld,%lld,%lld\n", s, m, l); + int64_t negS, negM, negL; + printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", + &negS, &negM, &negL)); + printf("%lld,%lld,%lld\n", negS, negM, negL); - int64_t negS, negM, negL; - printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", &negS, &negM, &negL)); - printf("%lld,%lld,%lld\n", negS, negM, negL); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_4.in b/tests/core/test_sscanf_4.in index b54176c5..c9e3b5f1 100644 --- a/tests/core/test_sscanf_4.in +++ b/tests/core/test_sscanf_4.in @@ -1,11 +1,8 @@ +#include <stdio.h> - #include <stdio.h> - - int main() - { - char pYear[16], pMonth[16], pDay[16], pDate[64]; - printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear)); - printf("day %s, month %s, year %s \n", pDay, pMonth, pYear); - return(0); - } -
\ No newline at end of file +int main() { + char pYear[16], pMonth[16], pDay[16], pDate[64]; + printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear)); + printf("day %s, month %s, year %s \n", pDay, pMonth, pYear); + return (0); +} diff --git a/tests/core/test_sscanf_5.in b/tests/core/test_sscanf_5.in index c3c1ed8a..c344258d 100644 --- a/tests/core/test_sscanf_5.in +++ b/tests/core/test_sscanf_5.in @@ -1,19 +1,13 @@ +#include "stdio.h" - #include "stdio.h" +static const char *colors[] = {" c black", ". c #001100", "X c #111100"}; - static const char *colors[] = { - " c black", - ". c #001100", - "X c #111100" - }; - - int main(){ - unsigned char code; - char color[32]; - int rcode; - for(int i = 0; i < 3; i++) { - rcode = sscanf(colors[i], "%c c %s", &code, color); - printf("%i, %c, %s\n", rcode, code, color); - } - } -
\ No newline at end of file +int main() { + unsigned char code; + char color[32]; + int rcode; + for (int i = 0; i < 3; i++) { + rcode = sscanf(colors[i], "%c c %s", &code, color); + printf("%i, %c, %s\n", rcode, code, color); + } +} diff --git a/tests/core/test_sscanf_6.in b/tests/core/test_sscanf_6.in index 2f2f58a3..63ede53f 100644 --- a/tests/core/test_sscanf_6.in +++ b/tests/core/test_sscanf_6.in @@ -1,15 +1,14 @@ - - #include <stdio.h> - #include <string.h> - int main() - { - char *date = "18.07.2013w"; - char c[10]; - memset(c, 0, 10); - int y, m, d, i; - i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); - printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i); - i = sscanf(date, "%d.%d.%3c", &d, &m, c); - printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char *date = "18.07.2013w"; + char c[10]; + memset(c, 0, 10); + int y, m, d, i; + i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, + y, c[0], i); + i = sscanf(date, "%d.%d.%3c", &d, &m, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, + y, c, i); +} diff --git a/tests/core/test_sscanf_caps.in b/tests/core/test_sscanf_caps.in index 39a90db5..b0936036 100644 --- a/tests/core/test_sscanf_caps.in +++ b/tests/core/test_sscanf_caps.in @@ -1,10 +1,8 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - unsigned int a; - float e, f, g; - sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g); - printf("%d %.1F %.1F %.1F\n", a, e, f, g); - } -
\ No newline at end of file +int main() { + unsigned int a; + float e, f, g; + sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g); + printf("%d %.1F %.1F %.1F\n", a, e, f, g); +} diff --git a/tests/core/test_sscanf_float.in b/tests/core/test_sscanf_float.in index e87d839a..29fe2d56 100644 --- a/tests/core/test_sscanf_float.in +++ b/tests/core/test_sscanf_float.in @@ -1,9 +1,10 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - float f1, f2, f3, f4, f5, f6, f7, f8, f9; - sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9); - printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); - } -
\ No newline at end of file +int main() { + float f1, f2, f3, f4, f5, f6, f7, f8, f9; + sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", + "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, + &f9); + printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, + f8, f9); +} diff --git a/tests/core/test_sscanf_hex.in b/tests/core/test_sscanf_hex.in index af6c158e..d8175e82 100644 --- a/tests/core/test_sscanf_hex.in +++ b/tests/core/test_sscanf_hex.in @@ -1,9 +1,7 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - unsigned int a, b; - sscanf("0x12AB 12AB", "%x %x", &a, &b); - printf("%d %d\n", a, b); - } -
\ No newline at end of file +int main() { + unsigned int a, b; + sscanf("0x12AB 12AB", "%x %x", &a, &b); + printf("%d %d\n", a, b); +} diff --git a/tests/core/test_sscanf_n.in b/tests/core/test_sscanf_n.in index 78142b3a..b383a3d7 100644 --- a/tests/core/test_sscanf_n.in +++ b/tests/core/test_sscanf_n.in @@ -1,21 +1,19 @@ +#include <stdio.h> +int main() { + char *line = "version 1.0"; + int i, l, lineno; + char word[80]; + if (sscanf(line, "%s%n", word, &l) != 1) { + printf("Header format error, line %d\n", lineno); + } + printf("[DEBUG] word 1: %s, l: %d\n", word, l); - #include<stdio.h> - int main() { - char *line = "version 1.0"; - int i, l, lineno; - char word[80]; - if (sscanf(line, "%s%n", word, &l) != 1) { - printf("Header format error, line %d\n", lineno); - } - printf("[DEBUG] word 1: %s, l: %d\n", word, l); - - int x = sscanf("one %n two", "%s %n", word, &l); - printf("%d,%s,%d\n", x, word, l); - { - int a, b, c, count; - count = sscanf("12345 6789", "%d %n%d", &a, &b, &c); - printf("%i %i %i %i\n", count, a, b, c); - } - return 0; - } -
\ No newline at end of file + int x = sscanf("one %n two", "%s %n", word, &l); + printf("%d,%s,%d\n", x, word, l); + { + int a, b, c, count; + count = sscanf("12345 6789", "%d %n%d", &a, &b, &c); + printf("%i %i %i %i\n", count, a, b, c); + } + return 0; +} diff --git a/tests/core/test_sscanf_other_whitespace.in b/tests/core/test_sscanf_other_whitespace.in index 224d1a23..467fa4f0 100644 --- a/tests/core/test_sscanf_other_whitespace.in +++ b/tests/core/test_sscanf_other_whitespace.in @@ -1,29 +1,23 @@ +#include <stdio.h> - #include<stdio.h> +int main() { + short int x; + short int y; - int main() { - short int x; - short int y; + const char* buffer[] = { + "\t2\t3\t", /* TAB - horizontal tab */ + "\t\t5\t\t7\t\t", "\n11\n13\n", /* LF - line feed */ + "\n\n17\n\n19\n\n", "\v23\v29\v", /* VT - vertical tab */ + "\v\v31\v\v37\v\v", "\f41\f43\f", /* FF - form feed */ + "\f\f47\f\f53\f\f", "\r59\r61\r", /* CR - carrage return */ + "\r\r67\r\r71\r\r"}; - const char* buffer[] = { - "\t2\t3\t", /* TAB - horizontal tab */ - "\t\t5\t\t7\t\t", - "\n11\n13\n", /* LF - line feed */ - "\n\n17\n\n19\n\n", - "\v23\v29\v", /* VT - vertical tab */ - "\v\v31\v\v37\v\v", - "\f41\f43\f", /* FF - form feed */ - "\f\f47\f\f53\f\f", - "\r59\r61\r", /* CR - carrage return */ - "\r\r67\r\r71\r\r" - }; + for (int i = 0; i < 10; ++i) { + x = 0; + y = 0; + sscanf(buffer[i], " %d %d ", &x, &y); + printf("%d, %d, ", x, y); + } - for (int i=0; i<10; ++i) { - x = 0; y = 0; - sscanf(buffer[i], " %d %d ", &x, &y); - printf("%d, %d, ", x, y); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_skip.in b/tests/core/test_sscanf_skip.in index 0faae7aa..f4ef8265 100644 --- a/tests/core/test_sscanf_skip.in +++ b/tests/core/test_sscanf_skip.in @@ -1,16 +1,15 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main() { + int val1; + printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1)); + printf("%d\n", val1); - int main(){ - int val1; - printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1)); - printf("%d\n", val1); + int64_t large, val2; + printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", + "%lld %*lld %ld %*d", &large, &val2)); + printf("%lld,%d\n", large, val2); - int64_t large, val2; - printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", "%lld %*lld %ld %*d", &large, &val2)); - printf("%lld,%d\n", large, val2); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_whitespace.in b/tests/core/test_sscanf_whitespace.in index 6947203f..8bcf1c7b 100644 --- a/tests/core/test_sscanf_whitespace.in +++ b/tests/core/test_sscanf_whitespace.in @@ -1,23 +1,16 @@ +#include <stdio.h> - #include<stdio.h> +int main() { + short int x; + short int y; - int main() { - short int x; - short int y; + const char* buffer[] = {"173,16", " 16,173", "183, 173", + " 17, 287", " 98, 123, "}; - const char* buffer[] = { - "173,16", - " 16,173", - "183, 173", - " 17, 287", - " 98, 123, " - }; + for (int i = 0; i < 5; ++i) { + sscanf(buffer[i], "%hd,%hd", &x, &y); + printf("%d:%d,%d ", i, x, y); + } - for (int i=0; i<5; ++i) { - sscanf(buffer[i], "%hd,%hd", &x, &y); - printf("%d:%d,%d ", i, x, y); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_stack.in b/tests/core/test_stack.in index 94e5d380..b2bca9a1 100644 --- a/tests/core/test_stack.in +++ b/tests/core/test_stack.in @@ -1,19 +1,16 @@ - - #include <stdio.h> - int test(int i) { - int x = 10; - if (i > 0) { - return test(i-1); - } - return int(&x); // both for the number, and forces x to not be nativized - } - int main(int argc, char **argv) - { - // We should get the same value for the first and last - stack has unwound - int x1 = test(argc - 2); - int x2 = test(100); - int x3 = test((argc - 2) / 4); - printf("*%d,%d*\n", x3-x1, x2 != x1); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int test(int i) { + int x = 10; + if (i > 0) { + return test(i - 1); + } + return int(&x); // both for the number, and forces x to not be nativized +} +int main(int argc, char **argv) { + // We should get the same value for the first and last - stack has unwound + int x1 = test(argc - 2); + int x2 = test(100); + int x3 = test((argc - 2) / 4); + printf("*%d,%d*\n", x3 - x1, x2 != x1); + return 0; +} diff --git a/tests/core/test_stack_byval.in b/tests/core/test_stack_byval.in index 565866ee..d7007d0a 100644 --- a/tests/core/test_stack_byval.in +++ b/tests/core/test_stack_byval.in @@ -1,25 +1,21 @@ - // We should also not blow up the stack with byval arguments - #include<stdio.h> - struct vec { - int x, y, z; - vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {} - static vec add(vec a, vec b) { - return vec(a.x+b.x, a.y+b.y, a.z+b.z); - } - }; - int main() { - int total = 0; - for (int i = 0; i < 1000; i++) { - for (int j = 0; j < 1000; j++) { - vec c(i+i%10, j*2, i%255); - vec d(j*2, j%255, i%120); - vec f = vec::add(c, d); - total += (f.x + f.y + f.z) % 100; - total %= 10240; - } - } - printf("sum:%d*\n", total); - return 0; - } - +#include <stdio.h> +struct vec { + int x, y, z; + vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {} + static vec add(vec a, vec b) { return vec(a.x + b.x, a.y + b.y, a.z + b.z); } +}; +int main() { + int total = 0; + for (int i = 0; i < 1000; i++) { + for (int j = 0; j < 1000; j++) { + vec c(i + i % 10, j * 2, i % 255); + vec d(j * 2, j % 255, i % 120); + vec f = vec::add(c, d); + total += (f.x + f.y + f.z) % 100; + total %= 10240; + } + } + printf("sum:%d*\n", total); + return 0; +} diff --git a/tests/core/test_stack_varargs.in b/tests/core/test_stack_varargs.in index 74b600bd..01c231af 100644 --- a/tests/core/test_stack_varargs.in +++ b/tests/core/test_stack_varargs.in @@ -1,16 +1,16 @@ - // We should not blow up the stack with numerous varargs - #include <stdio.h> - #include <stdlib.h> +#include <stdio.h> +#include <stdlib.h> - void func(int i) { - printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", - i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i); - } - int main() { - for (int i = 0; i < 1024; i++) - func(i); - printf("ok!\n"); - return 0; - } - +void func(int i) { + printf( + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d," + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", + i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, + i, i, i, i, i, i, i, i, i, i, i, i, i, i); +} +int main() { + for (int i = 0; i < 1024; i++) func(i); + printf("ok!\n"); + return 0; +} diff --git a/tests/core/test_stack_void.in b/tests/core/test_stack_void.in index 7e48a0f0..0e72e509 100644 --- a/tests/core/test_stack_void.in +++ b/tests/core/test_stack_void.in @@ -1,16 +1,34 @@ +#include <stdio.h> - #include <stdio.h> - - static char s[100]="aaaaa"; - static int func(void) { - if(s[0]!='a') return 0; - printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001); - return 0; - } - int main(){ - int i; - for(i=0;i<5000;i++) - func(); - printf(".ok.\n"); - } -
\ No newline at end of file +static char s[100] = "aaaaa"; +static int func(void) { + if (s[0] != 'a') return 0; + printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001); + return 0; +} +int main() { + int i; + for (i = 0; i < 5000; i++) func(); + printf(".ok.\n"); +} diff --git a/tests/core/test_static_variable.in b/tests/core/test_static_variable.in index 82fcadac..70b41324 100644 --- a/tests/core/test_static_variable.in +++ b/tests/core/test_static_variable.in @@ -1,26 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +struct DATA { + int value; - struct DATA - { - int value; + DATA() { value = 0; } +}; - DATA() - { - value = 0; - } - }; +DATA& GetData() { + static DATA data; - DATA & GetData() - { - static DATA data; + return data; +} - return data; - } - - int main() - { - GetData().value = 10; - printf( "value:%i", GetData().value ); - } -
\ No newline at end of file +int main() { + GetData().value = 10; + printf("value:%i", GetData().value); +} diff --git a/tests/core/test_statics.in b/tests/core/test_statics.in index 0935aade..d3302db5 100644 --- a/tests/core/test_statics.in +++ b/tests/core/test_statics.in @@ -1,39 +1,35 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +#define CONSTRLEN 32 - #define CONSTRLEN 32 +char *(*func)(char *, const char *) = NULL; - char * (*func)(char *, const char *) = NULL; +void conoutfv(const char *fmt) { + static char buf[CONSTRLEN]; + func(buf, fmt); // call by function pointer to make sure we test strcpy here + puts(buf); +} - void conoutfv(const char *fmt) - { - static char buf[CONSTRLEN]; - func(buf, fmt); // call by function pointer to make sure we test strcpy here - puts(buf); - } +struct XYZ { + float x, y, z; + XYZ(float a, float b, float c) : x(a), y(b), z(c) {} + static const XYZ &getIdentity() { + static XYZ iT(1, 2, 3); + return iT; + } +}; +struct S { + static const XYZ &getIdentity() { + static const XYZ iT(XYZ::getIdentity()); + return iT; + } +}; - struct XYZ { - float x, y, z; - XYZ(float a, float b, float c) : x(a), y(b), z(c) { } - static const XYZ& getIdentity() - { - static XYZ iT(1,2,3); - return iT; - } - }; - struct S { - static const XYZ& getIdentity() - { - static const XYZ iT(XYZ::getIdentity()); - return iT; - } - }; - - int main() { - func = &strcpy; - conoutfv("*staticccz*"); - printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, S::getIdentity().z); - return 0; - } -
\ No newline at end of file +int main() { + func = &strcpy; + conoutfv("*staticccz*"); + printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, + S::getIdentity().z); + return 0; +} diff --git a/tests/core/test_statvfs.in b/tests/core/test_statvfs.in index f9bd781a..72891505 100644 --- a/tests/core/test_statvfs.in +++ b/tests/core/test_statvfs.in @@ -1,26 +1,24 @@ +#include <stdio.h> +#include <errno.h> +#include <sys/statvfs.h> - #include <stdio.h> - #include <errno.h> - #include <sys/statvfs.h> +int main() { + struct statvfs s; - int main() { - struct statvfs s; + printf("result: %d\n", statvfs("/test", &s)); + printf("errno: %d\n", errno); - printf("result: %d\n", statvfs("/test", &s)); - printf("errno: %d\n", errno); + printf("f_bsize: %lu\n", s.f_bsize); + printf("f_frsize: %lu\n", s.f_frsize); + printf("f_blocks: %lu\n", s.f_blocks); + printf("f_bfree: %lu\n", s.f_bfree); + printf("f_bavail: %lu\n", s.f_bavail); + printf("f_files: %d\n", s.f_files > 5); + printf("f_ffree: %lu\n", s.f_ffree); + printf("f_favail: %lu\n", s.f_favail); + printf("f_fsid: %lu\n", s.f_fsid); + printf("f_flag: %lu\n", s.f_flag); + printf("f_namemax: %lu\n", s.f_namemax); - printf("f_bsize: %lu\n", s.f_bsize); - printf("f_frsize: %lu\n", s.f_frsize); - printf("f_blocks: %lu\n", s.f_blocks); - printf("f_bfree: %lu\n", s.f_bfree); - printf("f_bavail: %lu\n", s.f_bavail); - printf("f_files: %d\n", s.f_files > 5); - printf("f_ffree: %lu\n", s.f_ffree); - printf("f_favail: %lu\n", s.f_favail); - printf("f_fsid: %lu\n", s.f_fsid); - printf("f_flag: %lu\n", s.f_flag); - printf("f_namemax: %lu\n", s.f_namemax); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_std_cout_new.in b/tests/core/test_std_cout_new.in index 20895169..d1ab3c45 100644 --- a/tests/core/test_std_cout_new.in +++ b/tests/core/test_std_cout_new.in @@ -1,24 +1,21 @@ +#include <iostream> - #include <iostream> +struct NodeInfo { // structure that we want to transmit to our shaders + float x; + float y; + float s; + float c; +}; +const int nbNodes = 100; +NodeInfo* data = new NodeInfo[nbNodes]; // our data that will be transmitted + // using float texture. - struct NodeInfo { //structure that we want to transmit to our shaders - float x; - float y; - float s; - float c; - }; - const int nbNodes = 100; - NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture. +template <int i> +void printText(const char (&text)[i]) { + std::cout << text << std::endl; +} - template<int i> - void printText( const char (&text)[ i ] ) - { - std::cout << text << std::endl; - } - - int main() - { - printText( "some string constant" ); - return 0; - } -
\ No newline at end of file +int main() { + printText("some string constant"); + return 0; +} diff --git a/tests/core/test_std_exception.in b/tests/core/test_std_exception.in index 280faed2..4b5905d8 100644 --- a/tests/core/test_std_exception.in +++ b/tests/core/test_std_exception.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <exception> - #include <stdio.h> - #include <exception> - - int main() - { - std::exception e; - try { - throw e; - } catch(std::exception e) { - printf("caught std::exception\n"); - } - return 0; - } -
\ No newline at end of file +int main() { + std::exception e; + try { + throw e; + } + catch (std::exception e) { + printf("caught std::exception\n"); + } + return 0; +} diff --git a/tests/core/test_stdvec.in b/tests/core/test_stdvec.in index 884933c2..b370eb61 100644 --- a/tests/core/test_stdvec.in +++ b/tests/core/test_stdvec.in @@ -1,31 +1,25 @@ +#include <vector> +#include <stdio.h> - #include <vector> - #include <stdio.h> +struct S { + int a; + float b; +}; - struct S { - int a; - float b; - }; +void foo(int a, float b) { printf("%d:%.2f\n", a, b); } - void foo(int a, float b) - { - printf("%d:%.2f\n", a, b); - } +int main(int argc, char *argv[]) { + std::vector<S> ar; + S s; - int main ( int argc, char *argv[] ) - { - std::vector<S> ar; - S s; + s.a = 789; + s.b = 123.456f; + ar.push_back(s); - s.a = 789; - s.b = 123.456f; - ar.push_back(s); + s.a = 0; + s.b = 100.1f; + ar.push_back(s); - s.a = 0; - s.b = 100.1f; - ar.push_back(s); - - foo(ar[0].a, ar[0].b); - foo(ar[1].a, ar[1].b); - } -
\ No newline at end of file + foo(ar[0].a, ar[0].b); + foo(ar[1].a, ar[1].b); +} diff --git a/tests/core/test_strcasecmp.in b/tests/core/test_strcasecmp.in index 6186e50b..2fb69d1a 100644 --- a/tests/core/test_strcasecmp.in +++ b/tests/core/test_strcasecmp.in @@ -1,81 +1,79 @@ +#include <stdio.h> +#include <strings.h> +int sign(int x) { + if (x < 0) return -1; + if (x > 0) return 1; + return 0; +} +int main() { + printf("*\n"); - #include <stdio.h> - #include <strings.h> - int sign(int x) { - if (x < 0) return -1; - if (x > 0) return 1; - return 0; - } - int main() { - printf("*\n"); + printf("%d\n", sign(strcasecmp("hello", "hello"))); + printf("%d\n", sign(strcasecmp("hello1", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("iello", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); - printf("%d\n", sign(strcasecmp("hello", "hello"))); - printf("%d\n", sign(strcasecmp("hello1", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "hello1"))); - printf("%d\n", sign(strcasecmp("hello1", "hello1"))); - printf("%d\n", sign(strcasecmp("iello", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "iello"))); - printf("%d\n", sign(strcasecmp("A", "hello"))); - printf("%d\n", sign(strcasecmp("Z", "hello"))); - printf("%d\n", sign(strcasecmp("a", "hello"))); - printf("%d\n", sign(strcasecmp("z", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "a"))); - printf("%d\n", sign(strcasecmp("hello", "z"))); + printf("%d\n", sign(strcasecmp("Hello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); - printf("%d\n", sign(strcasecmp("Hello", "hello"))); - printf("%d\n", sign(strcasecmp("Hello1", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "hello1"))); - printf("%d\n", sign(strcasecmp("Hello1", "hello1"))); - printf("%d\n", sign(strcasecmp("Iello", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "iello"))); - printf("%d\n", sign(strcasecmp("A", "hello"))); - printf("%d\n", sign(strcasecmp("Z", "hello"))); - printf("%d\n", sign(strcasecmp("a", "hello"))); - printf("%d\n", sign(strcasecmp("z", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "a"))); - printf("%d\n", sign(strcasecmp("Hello", "z"))); + printf("%d\n", sign(strcasecmp("hello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("iello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); - printf("%d\n", sign(strcasecmp("hello", "Hello"))); - printf("%d\n", sign(strcasecmp("hello1", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "Hello1"))); - printf("%d\n", sign(strcasecmp("hello1", "Hello1"))); - printf("%d\n", sign(strcasecmp("iello", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "Iello"))); - printf("%d\n", sign(strcasecmp("A", "Hello"))); - printf("%d\n", sign(strcasecmp("Z", "Hello"))); - printf("%d\n", sign(strcasecmp("a", "Hello"))); - printf("%d\n", sign(strcasecmp("z", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "a"))); - printf("%d\n", sign(strcasecmp("hello", "z"))); + printf("%d\n", sign(strcasecmp("Hello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); - printf("%d\n", sign(strcasecmp("Hello", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello1", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "Hello1"))); - printf("%d\n", sign(strcasecmp("Hello1", "Hello1"))); - printf("%d\n", sign(strcasecmp("Iello", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "Iello"))); - printf("%d\n", sign(strcasecmp("A", "Hello"))); - printf("%d\n", sign(strcasecmp("Z", "Hello"))); - printf("%d\n", sign(strcasecmp("a", "Hello"))); - printf("%d\n", sign(strcasecmp("z", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "a"))); - printf("%d\n", sign(strcasecmp("Hello", "z"))); + printf("%d\n", sign(strncasecmp("hello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "hello1", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello1", 3))); + printf("%d\n", sign(strncasecmp("iello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "iello", 3))); + printf("%d\n", sign(strncasecmp("A", "hello", 3))); + printf("%d\n", sign(strncasecmp("Z", "hello", 3))); + printf("%d\n", sign(strncasecmp("a", "hello", 3))); + printf("%d\n", sign(strncasecmp("z", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "a", 3))); + printf("%d\n", sign(strncasecmp("hello", "z", 3))); - printf("%d\n", sign(strncasecmp("hello", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello1", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "hello1", 3))); - printf("%d\n", sign(strncasecmp("hello1", "hello1", 3))); - printf("%d\n", sign(strncasecmp("iello", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "iello", 3))); - printf("%d\n", sign(strncasecmp("A", "hello", 3))); - printf("%d\n", sign(strncasecmp("Z", "hello", 3))); - printf("%d\n", sign(strncasecmp("a", "hello", 3))); - printf("%d\n", sign(strncasecmp("z", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "a", 3))); - printf("%d\n", sign(strncasecmp("hello", "z", 3))); + printf("*\n"); - printf("*\n"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_strcmp_uni.in b/tests/core/test_strcmp_uni.in index 4ccd7db8..82819dde 100644 --- a/tests/core/test_strcmp_uni.in +++ b/tests/core/test_strcmp_uni.in @@ -1,11 +1,14 @@ - - #include <stdio.h> - #include <string.h> - int main() - { - #define TEST(func) { char *word = "WORD"; char wordEntry[2] = { -61,-126 }; /* "Â"; */ int cmp = func(word, wordEntry, 2); printf("Compare value " #func " is %d\n", cmp); } - TEST(strncmp); - TEST(strncasecmp); - TEST(memcmp); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { +#define TEST(func) \ + { \ + char *word = "WORD"; \ + char wordEntry[2] = {-61, -126}; /* "Â"; */ \ + int cmp = func(word, wordEntry, 2); \ + printf("Compare value " #func " is %d\n", cmp); \ + } + TEST(strncmp); + TEST(strncasecmp); + TEST(memcmp); +} diff --git a/tests/core/test_strftime.in b/tests/core/test_strftime.in index 1897c58a..4a3a7fda 100644 --- a/tests/core/test_strftime.in +++ b/tests/core/test_strftime.in @@ -1,153 +1,134 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> - #include <time.h> - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - void test(int result, const char* comment, const char* parsed = "") { - printf("%d",result); - if (!result) { - printf("\nERROR: %s (\"%s\")\n", comment, parsed); - } - } - - int cmp(const char *s1, const char *s2) { - for ( ; *s1 == *s2 ; s1++,s2++ ) { - if ( *s1 == '\0' ) - break; - } - - return (*s1 - *s2); - } - - int main() { - struct tm tm; - char s[1000]; - size_t size; - - tm.tm_sec = 4; - tm.tm_min = 23; - tm.tm_hour = 20; - tm.tm_mday = 21; - tm.tm_mon = 1; - tm.tm_year = 74; - tm.tm_wday = 4; - tm.tm_yday = 51; - tm.tm_isdst = 0; - - size = strftime(s, 1000, "", &tm); - test((size==0) && (*s=='\0'), "strftime test #1", s); - - size = strftime(s, 1000, "%a", &tm); - test((size==3) && !cmp(s, "Thu"), "strftime test #2", s); - - size = strftime(s, 1000, "%A", &tm); - test((size==8) && !cmp(s, "Thursday"), "strftime test #3", s); - - size = strftime(s, 1000, "%b", &tm); - test((size==3) && !cmp(s, "Feb"), "strftime test #4", s); - - size = strftime(s, 1000, "%B", &tm); - test((size==8) && !cmp(s, "February"), - "strftime test #5", s); - - size = strftime(s, 1000, "%d", &tm); - test((size==2) && !cmp(s, "21"), - "strftime test #6", s); - - size = strftime(s, 1000, "%H", &tm); - test((size==2) && !cmp(s, "20"), - "strftime test #7", s); - - size = strftime(s, 1000, "%I", &tm); - test((size==2) && !cmp(s, "08"), - "strftime test #8", s); - - size = strftime(s, 1000, "%j", &tm); - test((size==3) && !cmp(s, "052"), - "strftime test #9", s); - - size = strftime(s, 1000, "%m", &tm); - test((size==2) && !cmp(s, "02"), - "strftime test #10", s); - - size = strftime(s, 1000, "%M", &tm); - test((size==2) && !cmp(s, "23"), - "strftime test #11", s); - - size = strftime(s, 1000, "%p", &tm); - test((size==2) && !cmp(s, "PM"), - "strftime test #12", s); - - size = strftime(s, 1000, "%S", &tm); - test((size==2) && !cmp(s, "04"), - "strftime test #13", s); - - size = strftime(s, 1000, "%U", &tm); - test((size==2) && !cmp(s, "07"), - "strftime test #14", s); - - size = strftime(s, 1000, "%w", &tm); - test((size==1) && !cmp(s, "4"), - "strftime test #15", s); - - size = strftime(s, 1000, "%W", &tm); - test((size==2) && !cmp(s, "07"), - "strftime test #16", s); - - size = strftime(s, 1000, "%y", &tm); - test((size==2) && !cmp(s, "74"), - "strftime test #17", s); - - size = strftime(s, 1000, "%Y", &tm); - test((size==4) && !cmp(s, "1974"), - "strftime test #18", s); - - size = strftime(s, 1000, "%%", &tm); - test((size==1) && !cmp(s, "%"), - "strftime test #19", s); - - size = strftime(s, 5, "%Y", &tm); - test((size==4) && !cmp(s, "1974"), - "strftime test #20", s); - - size = strftime(s, 4, "%Y", &tm); - test((size==0), "strftime test #21", s); - - tm.tm_mon = 0; - tm.tm_mday = 1; - size = strftime(s, 10, "%U", &tm); - test((size==2) && !cmp(s, "00"), "strftime test #22", s); - - size = strftime(s, 10, "%W", &tm); - test((size==2) && !cmp(s, "00"), "strftime test #23", s); - - // 1/1/1973 was a Sunday and is in CW 1 - tm.tm_year = 73; - size = strftime(s, 10, "%W", &tm); - test((size==2) && !cmp(s, "01"), "strftime test #24", s); - - // 1/1/1978 was a Monday and is in CW 1 - tm.tm_year = 78; - size = strftime(s, 10, "%U", &tm); - test((size==2) && !cmp(s, "01"), "strftime test #25", s); - - // 2/1/1999 - tm.tm_year = 99; - tm.tm_yday = 1; - size = strftime(s, 10, "%G (%V)", &tm); - test((size==9) && !cmp(s, "1998 (53)"), "strftime test #26", s); +void test(int result, const char* comment, const char* parsed = "") { + printf("%d", result); + if (!result) { + printf("\nERROR: %s (\"%s\")\n", comment, parsed); + } +} - size = strftime(s, 10, "%g", &tm); - test((size==2) && !cmp(s, "98"), "strftime test #27", s); +int cmp(const char* s1, const char* s2) { + for (; *s1 == *s2; s1++, s2++) { + if (*s1 == '\0') break; + } - // 30/12/1997 - tm.tm_year = 97; - tm.tm_yday = 363; - size = strftime(s, 10, "%G (%V)", &tm); - test((size==9) && !cmp(s, "1998 (01)"), "strftime test #28", s); - - size = strftime(s, 10, "%g", &tm); - test((size==2) && !cmp(s, "98"), "strftime test #29", s); - } -
\ No newline at end of file + return (*s1 - *s2); +} + +int main() { + struct tm tm; + char s[1000]; + size_t size; + + tm.tm_sec = 4; + tm.tm_min = 23; + tm.tm_hour = 20; + tm.tm_mday = 21; + tm.tm_mon = 1; + tm.tm_year = 74; + tm.tm_wday = 4; + tm.tm_yday = 51; + tm.tm_isdst = 0; + + size = strftime(s, 1000, "", &tm); + test((size == 0) && (*s == '\0'), "strftime test #1", s); + + size = strftime(s, 1000, "%a", &tm); + test((size == 3) && !cmp(s, "Thu"), "strftime test #2", s); + + size = strftime(s, 1000, "%A", &tm); + test((size == 8) && !cmp(s, "Thursday"), "strftime test #3", s); + + size = strftime(s, 1000, "%b", &tm); + test((size == 3) && !cmp(s, "Feb"), "strftime test #4", s); + + size = strftime(s, 1000, "%B", &tm); + test((size == 8) && !cmp(s, "February"), "strftime test #5", s); + + size = strftime(s, 1000, "%d", &tm); + test((size == 2) && !cmp(s, "21"), "strftime test #6", s); + + size = strftime(s, 1000, "%H", &tm); + test((size == 2) && !cmp(s, "20"), "strftime test #7", s); + + size = strftime(s, 1000, "%I", &tm); + test((size == 2) && !cmp(s, "08"), "strftime test #8", s); + + size = strftime(s, 1000, "%j", &tm); + test((size == 3) && !cmp(s, "052"), "strftime test #9", s); + + size = strftime(s, 1000, "%m", &tm); + test((size == 2) && !cmp(s, "02"), "strftime test #10", s); + + size = strftime(s, 1000, "%M", &tm); + test((size == 2) && !cmp(s, "23"), "strftime test #11", s); + + size = strftime(s, 1000, "%p", &tm); + test((size == 2) && !cmp(s, "PM"), "strftime test #12", s); + + size = strftime(s, 1000, "%S", &tm); + test((size == 2) && !cmp(s, "04"), "strftime test #13", s); + + size = strftime(s, 1000, "%U", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #14", s); + + size = strftime(s, 1000, "%w", &tm); + test((size == 1) && !cmp(s, "4"), "strftime test #15", s); + + size = strftime(s, 1000, "%W", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #16", s); + + size = strftime(s, 1000, "%y", &tm); + test((size == 2) && !cmp(s, "74"), "strftime test #17", s); + + size = strftime(s, 1000, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #18", s); + + size = strftime(s, 1000, "%%", &tm); + test((size == 1) && !cmp(s, "%"), "strftime test #19", s); + + size = strftime(s, 5, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #20", s); + + size = strftime(s, 4, "%Y", &tm); + test((size == 0), "strftime test #21", s); + + tm.tm_mon = 0; + tm.tm_mday = 1; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #22", s); + + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #23", s); + + // 1/1/1973 was a Sunday and is in CW 1 + tm.tm_year = 73; + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #24", s); + + // 1/1/1978 was a Monday and is in CW 1 + tm.tm_year = 78; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #25", s); + + // 2/1/1999 + tm.tm_year = 99; + tm.tm_yday = 1; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (53)"), "strftime test #26", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #27", s); + + // 30/12/1997 + tm.tm_year = 97; + tm.tm_yday = 363; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (01)"), "strftime test #28", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #29", s); +} diff --git a/tests/core/test_strings.in b/tests/core/test_strings.in index 6c7e2366..3161b73f 100644 --- a/tests/core/test_strings.in +++ b/tests/core/test_strings.in @@ -1,53 +1,54 @@ - - #include <stdio.h> - #include <stdlib.h> - #include <string.h> - - int main(int argc, char **argv) - { - int x = 5, y = 9, magic = 7; // fool compiler with magic - memmove(&x, &y, magic-7); // 0 should not crash us - - int xx, yy, zz; - char s[32]; - int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s); - printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s); - - printf("%d\n", argc); - puts(argv[1]); - puts(argv[2]); - printf("%d\n", atoi(argv[3])+2); - const char *foolingthecompiler = "\rabcd"; - printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D! - printf("%s\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us! - printf("/* a comment */\n"); // Should not break the generated code! - printf("// another\n"); // Should not break the generated code! - - char* strdup_val = strdup("test"); - printf("%s\n", strdup_val); - free(strdup_val); - - { - char *one = "one 1 ONE !"; - char *two = "two 2 TWO ?"; - char three[1024]; - memset(three, '.', 1024); - three[50] = 0; - strncpy(three + argc, one + (argc/2), argc+1); - strncpy(three + argc*3, two + (argc/3), argc+2); - printf("waka %s\n", three); - } - - { - char *one = "string number one top notch"; - char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO"; - char three[1000]; - strcpy(three, &one[argc*2]); - char *four = strcat(three, &two[argc*3]); - printf("cat |%s|\n", three); - printf("returned |%s|\n", four); - } - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char **argv) { + int x = 5, y = 9, magic = 7; // fool compiler with magic + memmove(&x, &y, magic - 7); // 0 should not crash us + + int xx, yy, zz; + char s[32]; + int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, + &yy, &zz, s); + printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s); + + printf("%d\n", argc); + puts(argv[1]); + puts(argv[2]); + printf("%d\n", atoi(argv[3]) + 2); + const char *foolingthecompiler = "\rabcd"; + printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - + // should not be a 0 (end string) + // then a D! + printf("%s\n", NULL); // Should print '(null)', not the string at address 0, + // which is a real address for us! + printf("/* a comment */\n"); // Should not break the generated code! + printf("// another\n"); // Should not break the generated code! + + char *strdup_val = strdup("test"); + printf("%s\n", strdup_val); + free(strdup_val); + + { + char *one = "one 1 ONE !"; + char *two = "two 2 TWO ?"; + char three[1024]; + memset(three, '.', 1024); + three[50] = 0; + strncpy(three + argc, one + (argc / 2), argc + 1); + strncpy(three + argc * 3, two + (argc / 3), argc + 2); + printf("waka %s\n", three); + } + + { + char *one = "string number one top notch"; + char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO"; + char three[1000]; + strcpy(three, &one[argc * 2]); + char *four = strcat(three, &two[argc * 3]); + printf("cat |%s|\n", three); + printf("returned |%s|\n", four); + } + + return 0; +} diff --git a/tests/core/test_strndup.in b/tests/core/test_strndup.in index 938452a1..2457de0c 100644 --- a/tests/core/test_strndup.in +++ b/tests/core/test_strndup.in @@ -1,39 +1,38 @@ +//--------------- +//- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html +//--------------- - //--------------- - //- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html - //--------------- +#include <stdio.h> +#include <stdlib.h> +#include <string.h> - #include <stdio.h> - #include <stdlib.h> - #include <string.h> +int main(int argc, char** argv) { + const char* source = + "strndup - duplicate a specific number of bytes from a string"; - int main(int argc, char **argv) { - const char* source = "strndup - duplicate a specific number of bytes from a string"; + char* strdup_val = strndup(source, 0); + printf("1:%s\n", strdup_val); + free(strdup_val); - char* strdup_val = strndup(source, 0); - printf("1:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 7); + printf("2:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 7); - printf("2:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 1000); + printf("3:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 1000); - printf("3:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 60); + printf("4:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 60); - printf("4:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 19); + printf("5:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 19); - printf("5:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, -1); + printf("6:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, -1); - printf("6:%s\n", strdup_val); - free(strdup_val); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_strptime_days.in b/tests/core/test_strptime_days.in index d4f0c079..382ea8ef 100644 --- a/tests/core/test_strptime_days.in +++ b/tests/core/test_strptime_days.in @@ -1,34 +1,32 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> - #include <time.h> - #include <stdio.h> - #include <string.h> +static const struct { + const char *input; + const char *format; +} day_tests[] = {{"2000-01-01", "%Y-%m-%d"}, + {"03/03/00", "%D"}, + {"9/9/99", "%x"}, + {"19990502123412", "%Y%m%d%H%M%S"}, + {"2001 20 Mon", "%Y %U %a"}, + {"2006 4 Fri", "%Y %U %a"}, + {"2001 21 Mon", "%Y %W %a"}, + {"2013 29 Wed", "%Y %W %a"}, + {"2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"}, + {"2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"}, + {"2001 17 Tue", "%Y %U %a"}, + {"2001 8 Thursday", "%Y %W %a"}, }; - static const struct { - const char *input; - const char *format; - } day_tests[] = { - { "2000-01-01", "%Y-%m-%d"}, - { "03/03/00", "%D"}, - { "9/9/99", "%x"}, - { "19990502123412", "%Y%m%d%H%M%S"}, - { "2001 20 Mon", "%Y %U %a"}, - { "2006 4 Fri", "%Y %U %a"}, - { "2001 21 Mon", "%Y %W %a"}, - { "2013 29 Wed", "%Y %W %a"}, - { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"}, - { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"}, - { "2001 17 Tue", "%Y %U %a"}, - { "2001 8 Thursday", "%Y %W %a"}, - }; +int main() { + struct tm tm; - int main() { - struct tm tm; + for (int i = 0; i < sizeof(day_tests) / sizeof(day_tests[0]); ++i) { + memset(&tm, '\0', sizeof(tm)); + char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm); - for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) { - memset (&tm, '\0', sizeof (tm)); - char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm); - - printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday); - } - } -
\ No newline at end of file + printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", + (ptr != NULL && *ptr == '\0') ? "OK" : "ERR", tm.tm_mon + 1, + tm.tm_mday, 1900 + tm.tm_year, tm.tm_wday, tm.tm_yday); + } +} diff --git a/tests/core/test_strptime_reentrant.in b/tests/core/test_strptime_reentrant.in index b52d2399..b2a14d1d 100644 --- a/tests/core/test_strptime_reentrant.in +++ b/tests/core/test_strptime_reentrant.in @@ -1,47 +1,45 @@ - - #include <time.h> - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - int main () { - int result = 0; - struct tm tm; - - memset (&tm, 0xaa, sizeof (tm)); - - /* Test we don't crash on uninitialized struct tm. - Some fields might contain bogus values until everything - needed is initialized, but we shouldn't crash. */ - if (strptime ("2007", "%Y", &tm) == NULL - || strptime ("12", "%d", &tm) == NULL - || strptime ("Feb", "%b", &tm) == NULL - || strptime ("13", "%M", &tm) == NULL - || strptime ("21", "%S", &tm) == NULL - || strptime ("16", "%H", &tm) == NULL) { - printf("ERR: returned NULL"); - exit(EXIT_FAILURE); - } - - if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 - || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 - || tm.tm_wday != 1 || tm.tm_yday != 42) { - printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); - exit(EXIT_FAILURE); - } - - if (strptime ("8", "%d", &tm) == NULL) { - printf("ERR: strptime failed"); - exit(EXIT_FAILURE); - } - - if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 - || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 - || tm.tm_wday != 4 || tm.tm_yday != 38) { - printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); - exit(EXIT_FAILURE); - } - - printf("OK"); - } -
\ No newline at end of file +#include <time.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main() { + int result = 0; + struct tm tm; + + memset(&tm, 0xaa, sizeof(tm)); + + /* Test we don't crash on uninitialized struct tm. + Some fields might contain bogus values until everything + needed is initialized, but we shouldn't crash. */ + if (strptime("2007", "%Y", &tm) == NULL || + strptime("12", "%d", &tm) == NULL || strptime("Feb", "%b", &tm) == NULL || + strptime("13", "%M", &tm) == NULL || strptime("21", "%S", &tm) == NULL || + strptime("16", "%H", &tm) == NULL) { + printf("ERR: returned NULL"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 || + tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 || + tm.tm_wday != 1 || tm.tm_yday != 42) { + printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon + 1, + tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + if (strptime("8", "%d", &tm) == NULL) { + printf("ERR: strptime failed"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 || + tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 || + tm.tm_wday != 4 || tm.tm_yday != 38) { + printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon + 1, + tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + printf("OK"); +} diff --git a/tests/core/test_strptime_tm.in b/tests/core/test_strptime_tm.in index 29e40223..93cdb1d5 100644 --- a/tests/core/test_strptime_tm.in +++ b/tests/core/test_strptime_tm.in @@ -1,21 +1,27 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> - #include <time.h> - #include <stdio.h> - #include <string.h> +int main() { + struct tm tm; + char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); - int main() { - struct tm tm; - char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); - - printf("%s: %s, %d/%d/%d %d:%d:%d", - (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", - tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))), - tm.tm_mon+1, - tm.tm_mday, - tm.tm_year+1900, - tm.tm_hour, - tm.tm_min, - tm.tm_sec - ); - } -
\ No newline at end of file + printf( + "%s: %s, %d/%d/%d %d:%d:%d", (ptr != NULL && *ptr == '\0') ? "OK" : "ERR", + tm.tm_wday == 0 + ? "Sun" + : (tm.tm_wday == 1 + ? "Mon" + : (tm.tm_wday == 2 + ? "Tue" + : (tm.tm_wday == 3 + ? "Wed" + : (tm.tm_wday == 4 + ? "Thu" + : (tm.tm_wday == 5 + ? "Fri" + : (tm.tm_wday == 6 ? "Sat" + : "ERR")))))), + tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, + tm.tm_sec); +} diff --git a/tests/core/test_strstr.in b/tests/core/test_strstr.in index ab049cac..8aa56d4a 100644 --- a/tests/core/test_strstr.in +++ b/tests/core/test_strstr.in @@ -1,35 +1,32 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +int main() { + printf("%d\n", !!strstr("\\n", "\\n")); + printf("%d\n", !!strstr("cheezy", "ez")); + printf("%d\n", !!strstr("cheeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez")); + printf("%d\n", !!strstr("che1ezy", "ez")); + printf("%d\n", !!strstr("che1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "ezy")); + printf("%d\n", !!strstr("ce1ezyt", "ezy")); + printf("%d\n", !!strstr("ce1ez1y", "ezy")); + printf("%d\n", !!strstr("cheezy", "a")); + printf("%d\n", !!strstr("cheezy", "b")); + printf("%d\n", !!strstr("cheezy", "c")); + printf("%d\n", !!strstr("cheezy", "d")); + printf("%d\n", !!strstr("cheezy", "g")); + printf("%d\n", !!strstr("cheezy", "h")); + printf("%d\n", !!strstr("cheezy", "i")); + printf("%d\n", !!strstr("cheezy", "e")); + printf("%d\n", !!strstr("cheezy", "x")); + printf("%d\n", !!strstr("cheezy", "y")); + printf("%d\n", !!strstr("cheezy", "z")); + printf("%d\n", !!strstr("cheezy", "_")); - int main() - { - printf("%d\n", !!strstr("\\n", "\\n")); - printf("%d\n", !!strstr("cheezy", "ez")); - printf("%d\n", !!strstr("cheeezy", "ez")); - printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez")); - printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez")); - printf("%d\n", !!strstr("che1ezy", "ez")); - printf("%d\n", !!strstr("che1ezy", "che")); - printf("%d\n", !!strstr("ce1ezy", "che")); - printf("%d\n", !!strstr("ce1ezy", "ezy")); - printf("%d\n", !!strstr("ce1ezyt", "ezy")); - printf("%d\n", !!strstr("ce1ez1y", "ezy")); - printf("%d\n", !!strstr("cheezy", "a")); - printf("%d\n", !!strstr("cheezy", "b")); - printf("%d\n", !!strstr("cheezy", "c")); - printf("%d\n", !!strstr("cheezy", "d")); - printf("%d\n", !!strstr("cheezy", "g")); - printf("%d\n", !!strstr("cheezy", "h")); - printf("%d\n", !!strstr("cheezy", "i")); - printf("%d\n", !!strstr("cheezy", "e")); - printf("%d\n", !!strstr("cheezy", "x")); - printf("%d\n", !!strstr("cheezy", "y")); - printf("%d\n", !!strstr("cheezy", "z")); - printf("%d\n", !!strstr("cheezy", "_")); - - const char *str = "a big string"; - printf("%d\n", strstr(str, "big") - str); - return 0; - } -
\ No newline at end of file + const char *str = "a big string"; + printf("%d\n", strstr(str, "big") - str); + return 0; +} diff --git a/tests/core/test_strtok.in b/tests/core/test_strtok.in index 6391b9b0..6ef57191 100644 --- a/tests/core/test_strtok.in +++ b/tests/core/test_strtok.in @@ -1,20 +1,20 @@ +#include <stdio.h> +#include <string.h> - #include<stdio.h> - #include<string.h> +int main() { + char test[80], blah[80]; + char *sep = "\\/:;=-"; + char *word, *phrase, *brkt, *brkb; - int main() { - char test[80], blah[80]; - char *sep = "\\/:;=-"; - char *word, *phrase, *brkt, *brkb; + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - - for (word = strtok_r(test, sep, &brkt); word; word = strtok_r(NULL, sep, &brkt)) { - strcpy(blah, "blah:blat:blab:blag"); - for (phrase = strtok_r(blah, sep, &brkb); phrase; phrase = strtok_r(NULL, sep, &brkb)) { - printf("at %s:%s\n", word, phrase); - } - } - return 0; - } -
\ No newline at end of file + for (word = strtok_r(test, sep, &brkt); word; + word = strtok_r(NULL, sep, &brkt)) { + strcpy(blah, "blah:blat:blab:blag"); + for (phrase = strtok_r(blah, sep, &brkb); phrase; + phrase = strtok_r(NULL, sep, &brkb)) { + printf("at %s:%s\n", word, phrase); + } + } + return 0; +} diff --git a/tests/core/test_strtol_bin.in b/tests/core/test_strtol_bin.in index 972853ba..e54e0173 100644 --- a/tests/core/test_strtol_bin.in +++ b/tests/core/test_strtol_bin.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; - int main() { - const char *STRING = "1 -101 +1011"; - char *end_char; + // defined base + long l4 = strtol(STRING, &end_char, 2); + long l5 = strtol(end_char, &end_char, 2); + long l6 = strtol(end_char, NULL, 2); - // defined base - long l4 = strtol(STRING, &end_char, 2); - long l5 = strtol(end_char, &end_char, 2); - long l6 = strtol(end_char, NULL, 2); - - printf("%d%d%d\n", l4==1, l5==-5, l6==11); - return 0; - } -
\ No newline at end of file + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/tests/core/test_strtol_dec.in b/tests/core/test_strtol_dec.in index 496e5dc8..56053521 100644 --- a/tests/core/test_strtol_dec.in +++ b/tests/core/test_strtol_dec.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; - int main() { - const char *STRING = "4 -38 +4711"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 10); + long l5 = strtol(end_char, &end_char, 10); + long l6 = strtol(end_char, NULL, 10); - // defined base - long l4 = strtol(STRING, &end_char, 10); - long l5 = strtol(end_char, &end_char, 10); - long l6 = strtol(end_char, NULL, 10); - - printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/tests/core/test_strtol_hex.in b/tests/core/test_strtol_hex.in index f11d786a..65a43ed0 100644 --- a/tests/core/test_strtol_hex.in +++ b/tests/core/test_strtol_hex.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0x4 -0x3A +0xDEAD"; + char *end_char; - int main() { - const char *STRING = "0x4 -0x3A +0xDEAD"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 16); + long l5 = strtol(end_char, &end_char, 16); + long l6 = strtol(end_char, NULL, 16); - // defined base - long l4 = strtol(STRING, &end_char, 16); - long l5 = strtol(end_char, &end_char, 16); - long l6 = strtol(end_char, NULL, 16); - - printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdead, l4==0x4, l5==-0x3a, l6==0xdead); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdead, l4 == 0x4, + l5 == -0x3a, l6 == 0xdead); + return 0; +} diff --git a/tests/core/test_strtol_oct.in b/tests/core/test_strtol_oct.in index a50166a4..94b9c3ff 100644 --- a/tests/core/test_strtol_oct.in +++ b/tests/core/test_strtol_oct.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; - int main() { - const char *STRING = "0 -035 +04711"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 8); + long l5 = strtol(end_char, &end_char, 8); + long l6 = strtol(end_char, NULL, 8); - // defined base - long l4 = strtol(STRING, &end_char, 8); - long l5 = strtol(end_char, &end_char, 8); - long l6 = strtol(end_char, NULL, 8); - - printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/tests/core/test_strtoll_bin.in b/tests/core/test_strtoll_bin.in index ed3c4acf..cbe5546f 100644 --- a/tests/core/test_strtoll_bin.in +++ b/tests/core/test_strtoll_bin.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; - int main() { - const char *STRING = "1 -101 +1011"; - char *end_char; + // defined base + long long int l4 = strtoll(STRING, &end_char, 2); + long long int l5 = strtoll(end_char, &end_char, 2); + long long int l6 = strtoll(end_char, NULL, 2); - // defined base - long long int l4 = strtoll(STRING, &end_char, 2); - long long int l5 = strtoll(end_char, &end_char, 2); - long long int l6 = strtoll(end_char, NULL, 2); - - printf("%d%d%d\n", l4==1, l5==-5, l6==11); - return 0; - } -
\ No newline at end of file + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/tests/core/test_strtoll_dec.in b/tests/core/test_strtoll_dec.in index fbd5749c..f4d2950e 100644 --- a/tests/core/test_strtoll_dec.in +++ b/tests/core/test_strtoll_dec.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; - int main() { - const char *STRING = "4 -38 +4711"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 10); + long long int l5 = strtoll(end_char, &end_char, 10); + long long int l6 = strtoll(end_char, NULL, 10); - // defined base - long long int l4 = strtoll(STRING, &end_char, 10); - long long int l5 = strtoll(end_char, &end_char, 10); - long long int l6 = strtoll(end_char, NULL, 10); - - printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/tests/core/test_strtoll_hex.in b/tests/core/test_strtoll_hex.in index 333fe512..a432d0dd 100644 --- a/tests/core/test_strtoll_hex.in +++ b/tests/core/test_strtoll_hex.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0x4 -0x3A +0xDEADBEEF"; + char *end_char; - int main() { - const char *STRING = "0x4 -0x3A +0xDEADBEEF"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 16); + long long int l5 = strtoll(end_char, &end_char, 16); + long long int l6 = strtoll(end_char, NULL, 16); - // defined base - long long int l4 = strtoll(STRING, &end_char, 16); - long long int l5 = strtoll(end_char, &end_char, 16); - long long int l6 = strtoll(end_char, NULL, 16); - - printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdeadbeef, l4==0x4, l5==-0x3a, l6==0xdeadbeef); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdeadbeef, l4 == 0x4, + l5 == -0x3a, l6 == 0xdeadbeef); + return 0; +} diff --git a/tests/core/test_strtoll_oct.in b/tests/core/test_strtoll_oct.in index 260c7245..e5e12e24 100644 --- a/tests/core/test_strtoll_oct.in +++ b/tests/core/test_strtoll_oct.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; - int main() { - const char *STRING = "0 -035 +04711"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 8); + long long int l5 = strtoll(end_char, &end_char, 8); + long long int l6 = strtoll(end_char, NULL, 8); - // defined base - long long int l4 = strtoll(STRING, &end_char, 8); - long long int l5 = strtoll(end_char, &end_char, 8); - long long int l6 = strtoll(end_char, NULL, 8); - - printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/tests/core/test_structs.in b/tests/core/test_structs.in index 47158351..2d48a9aa 100644 --- a/tests/core/test_structs.in +++ b/tests/core/test_structs.in @@ -1,22 +1,21 @@ - - #include <stdio.h> - struct S - { - int x, y; - }; - int main() - { - S a, b; - a.x = 5; a.y = 6; - b.x = 101; b.y = 7009; - S *c, *d; - c = &a; - c->x *= 2; - c = &b; - c->y -= 1; - d = c; - d->y += 10; - printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, d->y); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct S { + int x, y; +}; +int main() { + S a, b; + a.x = 5; + a.y = 6; + b.x = 101; + b.y = 7009; + S *c, *d; + c = &a; + c->x *= 2; + c = &b; + c->y -= 1; + d = c; + d->y += 10; + printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, + d->y); + return 0; +} diff --git a/tests/core/test_time_c.in b/tests/core/test_time_c.in index 57b47217..9719464c 100644 --- a/tests/core/test_time_c.in +++ b/tests/core/test_time_c.in @@ -1,9 +1,7 @@ +#include <time.h> +#include <stdio.h> - #include <time.h> - #include <stdio.h> - - int main() { - time_t t = time(0); - printf("time: %s\n", ctime(&t)); - } -
\ No newline at end of file +int main() { + time_t t = time(0); + printf("time: %s\n", ctime(&t)); +} diff --git a/tests/core/test_timeb.in b/tests/core/test_timeb.in index baaefb8c..1e59f301 100644 --- a/tests/core/test_timeb.in +++ b/tests/core/test_timeb.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <assert.h> +#include <sys/timeb.h> - #include <stdio.h> - #include <assert.h> - #include <sys/timeb.h> - - int main() { - timeb tb; - tb.timezone = 1; - printf("*%d\n", ftime(&tb)); - assert(tb.time > 10000); - assert(tb.timezone == 0); - assert(tb.dstflag == 0); - return 0; - } -
\ No newline at end of file +int main() { + timeb tb; + tb.timezone = 1; + printf("*%d\n", ftime(&tb)); + assert(tb.time > 10000); + assert(tb.timezone == 0); + assert(tb.dstflag == 0); + return 0; +} diff --git a/tests/core/test_tinyfuncstr.in b/tests/core/test_tinyfuncstr.in index ea07ff33..fd1c9563 100644 --- a/tests/core/test_tinyfuncstr.in +++ b/tests/core/test_tinyfuncstr.in @@ -1,13 +1,11 @@ +#include <stdio.h> - #include <stdio.h> +struct Class { + static char *name1() { return "nameA"; } + char *name2() { return "nameB"; } +}; - struct Class { - static char *name1() { return "nameA"; } - char *name2() { return "nameB"; } - }; - - int main() { - printf("*%s,%s*\n", Class::name1(), (new Class())->name2()); - return 0; - } -
\ No newline at end of file +int main() { + printf("*%s,%s*\n", Class::name1(), (new Class())->name2()); + return 0; +} diff --git a/tests/core/test_transtrcase.in b/tests/core/test_transtrcase.in index 0592405e..a19fcb6e 100644 --- a/tests/core/test_transtrcase.in +++ b/tests/core/test_transtrcase.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char szToupr[] = "hello, "; - char szTolwr[] = "EMSCRIPTEN"; - strupr(szToupr); - strlwr(szTolwr); - printf(szToupr); - printf(szTolwr); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char szToupr[] = "hello, "; + char szTolwr[] = "EMSCRIPTEN"; + strupr(szToupr); + strlwr(szTolwr); + printf(szToupr); + printf(szTolwr); + return 0; +} diff --git a/tests/core/test_trickystring.in b/tests/core/test_trickystring.in index 95744369..2735ef7c 100644 --- a/tests/core/test_trickystring.in +++ b/tests/core/test_trickystring.in @@ -1,26 +1,16 @@ +#include <stdio.h> - #include <stdio.h> +typedef struct { + int (*f)(void *); + void *d; + char s[16]; +} LMEXFunctionStruct; - typedef struct - { - int (*f)(void *); - void *d; - char s[16]; - } LMEXFunctionStruct; +int f(void *user) { return 0; } - int f(void *user) - { - return 0; - } +static LMEXFunctionStruct const a[] = {{f, (void *)(int)'a', "aa"}}; - static LMEXFunctionStruct const a[] = - { - {f, (void *)(int)'a', "aa"} - }; - - int main() - { - printf("ok\n"); - return a[0].f(a[0].d); - } -
\ No newline at end of file +int main() { + printf("ok\n"); + return a[0].f(a[0].d); +} diff --git a/tests/core/test_typeid.in b/tests/core/test_typeid.in index fc777183..1f87e66e 100644 --- a/tests/core/test_typeid.in +++ b/tests/core/test_typeid.in @@ -1,53 +1,52 @@ - - #include <stdio.h> - #include <string.h> - #include <typeinfo> - int main() { - printf("*\n"); - #define MAX 100 - int ptrs[MAX]; - int groups[MAX]; - memset(ptrs, 0, MAX*sizeof(int)); - memset(groups, 0, MAX*sizeof(int)); - int next_group = 1; - #define TEST(X) { \ - int ptr = (int)&typeid(X); \ - int group = 0; \ - int i; \ - for (i = 0; i < MAX; i++) { \ - if (!groups[i]) break; \ - if (ptrs[i] == ptr) { \ - group = groups[i]; \ - break; \ - } \ - } \ - if (!group) { \ - groups[i] = group = next_group++; \ - ptrs[i] = ptr; \ - } \ - printf("%s:%d\n", #X, group); \ - } - TEST(int); - TEST(unsigned int); - TEST(unsigned); - TEST(signed int); - TEST(long); - TEST(unsigned long); - TEST(signed long); - TEST(long long); - TEST(unsigned long long); - TEST(signed long long); - TEST(short); - TEST(unsigned short); - TEST(signed short); - TEST(char); - TEST(unsigned char); - TEST(signed char); - TEST(float); - TEST(double); - TEST(long double); - TEST(void); - TEST(void*); - printf("*\n"); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +#include <typeinfo> +int main() { + printf("*\n"); +#define MAX 100 + int ptrs[MAX]; + int groups[MAX]; + memset(ptrs, 0, MAX * sizeof(int)); + memset(groups, 0, MAX * sizeof(int)); + int next_group = 1; +#define TEST(X) \ + { \ + int ptr = (int)&typeid(X); \ + int group = 0; \ + int i; \ + for (i = 0; i < MAX; i++) { \ + if (!groups[i]) break; \ + if (ptrs[i] == ptr) { \ + group = groups[i]; \ + break; \ + } \ + } \ + if (!group) { \ + groups[i] = group = next_group++; \ + ptrs[i] = ptr; \ + } \ + printf("%s:%d\n", #X, group); \ + } + TEST(int); + TEST(unsigned int); + TEST(unsigned); + TEST(signed int); + TEST(long); + TEST(unsigned long); + TEST(signed long); + TEST(long long); + TEST(unsigned long long); + TEST(signed long long); + TEST(short); + TEST(unsigned short); + TEST(signed short); + TEST(char); + TEST(unsigned char); + TEST(signed char); + TEST(float); + TEST(double); + TEST(long double); + TEST(void); + TEST(void*); + printf("*\n"); +} diff --git a/tests/core/test_uname.in b/tests/core/test_uname.in index 5ea40b06..780a754b 100644 --- a/tests/core/test_uname.in +++ b/tests/core/test_uname.in @@ -1,16 +1,14 @@ +#include <stdio.h> +#include <sys/utsname.h> - #include <stdio.h> - #include <sys/utsname.h> - - int main() { - struct utsname u; - printf("ret: %d\n", uname(&u)); - printf("sysname: %s\n", u.sysname); - printf("nodename: %s\n", u.nodename); - printf("release: %s\n", u.release); - printf("version: %s\n", u.version); - printf("machine: %s\n", u.machine); - printf("invalid: %d\n", uname(0)); - return 0; - } -
\ No newline at end of file +int main() { + struct utsname u; + printf("ret: %d\n", uname(&u)); + printf("sysname: %s\n", u.sysname); + printf("nodename: %s\n", u.nodename); + printf("release: %s\n", u.release); + printf("version: %s\n", u.version); + printf("machine: %s\n", u.machine); + printf("invalid: %d\n", uname(0)); + return 0; +} diff --git a/tests/core/test_utf.in b/tests/core/test_utf.in index 29cb6eac..87731186 100644 --- a/tests/core/test_utf.in +++ b/tests/core/test_utf.in @@ -1,13 +1,15 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - int main() { - char *c = "μ†ℱ ╋ℯ╳╋ 😇"; - printf("%d %d %d %d %s\n", c[0]&0xff, c[1]&0xff, c[2]&0xff, c[3]&0xff, c); - emscripten_run_script( - "cheez = _malloc(100);" - "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);" - "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, 'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, 'i8')&0xff, ]);"); - } -
\ No newline at end of file +int main() { + char *c = "μ†ℱ ╋ℯ╳╋ 😇"; + printf("%d %d %d %d %s\n", c[0] & 0xff, c[1] & 0xff, c[2] & 0xff, c[3] & 0xff, + c); + emscripten_run_script( + "cheez = _malloc(100);" + "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);" + "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, " + "'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, " + "Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, " + "'i8')&0xff, ]);"); +} diff --git a/tests/core/test_varargs.in b/tests/core/test_varargs.in index d169c151..653a6557 100644 --- a/tests/core/test_varargs.in +++ b/tests/core/test_varargs.in @@ -1,103 +1,112 @@ +#include <stdio.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdarg.h> - - void vary(const char *s, ...) - { - va_list v; - va_start(v, s); - char d[20]; - vsnprintf(d, 20, s, v); - puts(d); - - // Try it with copying - va_list tempva; - va_copy(tempva, v); - vsnprintf(d, 20, s, tempva); - puts(d); - - va_end(v); - } - - void vary2(char color, const char *s, ...) - { - va_list v; - va_start(v, s); - char d[21]; - d[0] = color; - vsnprintf(d+1, 20, s, v); - puts(d); - va_end(v); - } - - void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration) - { - while(count > 0) - { - const char* string = va_arg(ap, const char*); - printf("%s", string); - count--; - } - printf("\n"); - } - - void varags_listoffsets_list_copy(int count, va_list ap, int iteration) - { - va_list ap_copy; - va_copy(ap_copy, ap); - varargs_listoffsets_list_evaluate(count, ap_copy, iteration); - va_end(ap_copy); - } - - void varargs_listoffsets_args(int type, int count, ...) - { - va_list ap; - va_start(ap, count); - - // evaluate a copied list - varags_listoffsets_list_copy(count, ap, 1); - varags_listoffsets_list_copy(count, ap, 2); - varags_listoffsets_list_copy(count, ap, 3); - varags_listoffsets_list_copy(count, ap, 4); - - varargs_listoffsets_list_evaluate(count, ap, 1); - - // NOTE: we expect this test to fail, so we will check the stdout for <BAD+0><BAD+1>..... - varargs_listoffsets_list_evaluate(count, ap, 2); - - // NOTE: this test has to work again, as we restart the list - va_end(ap); - va_start(ap, count); - varargs_listoffsets_list_evaluate(count, ap, 3); - va_end(ap); - } - - void varargs_listoffsets_main() - { - varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>"); - } - - #define GETMAX(pref, type) type getMax##pref(int num, ...) { va_list vv; va_start(vv, num); type maxx = va_arg(vv, type); for (int i = 1; i < num; i++) { type curr = va_arg(vv, type); maxx = curr > maxx ? curr : maxx; } va_end(vv); return maxx; } - GETMAX(i, int); - GETMAX(D, double); - - int main(int argc, char **argv) { - vary("*cheez: %d+%d*", 0, 24); // Also tests that '0' is not special as an array ender - vary("*albeit*"); // Should not fail with no var args in vararg function - vary2('Q', "%d*", 85); - - int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19); - printf("maxxi:%d*\n", maxxi); - double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, (double)-10.1, (double)19.1, (double)2); - printf("maxxD:%.2f*\n", (float)maxxD); - - // And, as a function pointer - void (*vfp)(const char *s, ...) = argc == 1211 ? NULL : vary; - vfp("*vfp:%d,%d*", 22, 199); - - // ensure lists work properly when copied, reinited etc. - varargs_listoffsets_main(); - - return 0; - } -
\ No newline at end of file +void vary(const char *s, ...) { + va_list v; + va_start(v, s); + char d[20]; + vsnprintf(d, 20, s, v); + puts(d); + + // Try it with copying + va_list tempva; + va_copy(tempva, v); + vsnprintf(d, 20, s, tempva); + puts(d); + + va_end(v); +} + +void vary2(char color, const char *s, ...) { + va_list v; + va_start(v, s); + char d[21]; + d[0] = color; + vsnprintf(d + 1, 20, s, v); + puts(d); + va_end(v); +} + +void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration) { + while (count > 0) { + const char *string = va_arg(ap, const char *); + printf("%s", string); + count--; + } + printf("\n"); +} + +void varags_listoffsets_list_copy(int count, va_list ap, int iteration) { + va_list ap_copy; + va_copy(ap_copy, ap); + varargs_listoffsets_list_evaluate(count, ap_copy, iteration); + va_end(ap_copy); +} + +void varargs_listoffsets_args(int type, int count, ...) { + va_list ap; + va_start(ap, count); + + // evaluate a copied list + varags_listoffsets_list_copy(count, ap, 1); + varags_listoffsets_list_copy(count, ap, 2); + varags_listoffsets_list_copy(count, ap, 3); + varags_listoffsets_list_copy(count, ap, 4); + + varargs_listoffsets_list_evaluate(count, ap, 1); + + // NOTE: we expect this test to fail, so we will check the stdout for + // <BAD+0><BAD+1>..... + varargs_listoffsets_list_evaluate(count, ap, 2); + + // NOTE: this test has to work again, as we restart the list + va_end(ap); + va_start(ap, count); + varargs_listoffsets_list_evaluate(count, ap, 3); + va_end(ap); +} + +void varargs_listoffsets_main() { + varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", + "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", + "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", + "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", + "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>"); +} + +#define GETMAX(pref, type) \ + type getMax##pref(int num, ...) { \ + va_list vv; \ + va_start(vv, num); \ + type maxx = va_arg(vv, type); \ + for (int i = 1; i < num; i++) { \ + type curr = va_arg(vv, type); \ + maxx = curr > maxx ? curr : maxx; \ + } \ + va_end(vv); \ + return maxx; \ + } +GETMAX(i, int); +GETMAX(D, double); + +int main(int argc, char **argv) { + vary("*cheez: %d+%d*", 0, + 24); // Also tests that '0' is not special as an array ender + vary("*albeit*"); // Should not fail with no var args in vararg function + vary2('Q', "%d*", 85); + + int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19); + printf("maxxi:%d*\n", maxxi); + double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, + (double)-10.1, (double)19.1, (double)2); + printf("maxxD:%.2f*\n", (float)maxxD); + + // And, as a function pointer + void (*vfp)(const char * s, ...) = argc == 1211 ? NULL : vary; + vfp("*vfp:%d,%d*", 22, 199); + + // ensure lists work properly when copied, reinited etc. + varargs_listoffsets_main(); + + return 0; +} diff --git a/tests/core/test_vprintf.in b/tests/core/test_vprintf.in index fcaad9d9..a8af5735 100644 --- a/tests/core/test_vprintf.in +++ b/tests/core/test_vprintf.in @@ -1,18 +1,16 @@ +#include <stdio.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdarg.h> +void print(char* format, ...) { + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); +} - void print(char* format, ...) { - va_list args; - va_start (args, format); - vprintf (format, args); - va_end (args); - } +int main() { + print("Call with %d variable argument.\n", 1); + print("Call with %d variable %s.\n", 2, "arguments"); - int main () { - print("Call with %d variable argument.\n", 1); - print("Call with %d variable %s.\n", 2, "arguments"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_vsnprintf.in b/tests/core/test_vsnprintf.in index 938729b6..85f91e94 100644 --- a/tests/core/test_vsnprintf.in +++ b/tests/core/test_vsnprintf.in @@ -1,44 +1,41 @@ +#include <stdio.h> +#include <stdarg.h> +#include <stdint.h> - #include <stdio.h> - #include <stdarg.h> - #include <stdint.h> +void printy(const char *f, ...) { + char buffer[256]; + va_list args; + va_start(args, f); + vsnprintf(buffer, 256, f, args); + puts(buffer); + va_end(args); +} - void printy(const char *f, ...) - { - char buffer[256]; - va_list args; - va_start(args, f); - vsnprintf(buffer, 256, f, args); - puts(buffer); - va_end(args); - } +int main(int argc, char **argv) { + int64_t x = argc - 1; + int64_t y = argc - 1 + 0x400000; + if (x % 3 == 2) y *= 2; - int main(int argc, char **argv) { - int64_t x = argc - 1; - int64_t y = argc - 1 + 0x400000; - if (x % 3 == 2) y *= 2; + printy("0x%llx_0x%llx", x, y); + printy("0x%llx_0x%llx", x, x); + printy("0x%llx_0x%llx", y, x); + printy("0x%llx_0x%llx", y, y); - printy("0x%llx_0x%llx", x, y); - printy("0x%llx_0x%llx", x, x); - printy("0x%llx_0x%llx", y, x); - printy("0x%llx_0x%llx", y, y); + { + uint64_t A = 0x800000; + uint64_t B = 0x800000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x800; + uint64_t B = 0x12340000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x000009182746756; + uint64_t B = 0x192837465631ACBDULL; + printy("0x%llx_0x%llx", A, B); + } - { - uint64_t A = 0x800000; - uint64_t B = 0x800000000000ULL; - printy("0x%llx_0x%llx", A, B); - } - { - uint64_t A = 0x800; - uint64_t B = 0x12340000000000ULL; - printy("0x%llx_0x%llx", A, B); - } - { - uint64_t A = 0x000009182746756; - uint64_t B = 0x192837465631ACBDULL; - printy("0x%llx_0x%llx", A, B); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_white_list_exception.in b/tests/core/test_white_list_exception.in index c7c29c35..2944f9fe 100644 --- a/tests/core/test_white_list_exception.in +++ b/tests/core/test_white_list_exception.in @@ -1,22 +1,21 @@ +#include <stdio.h> - #include <stdio.h> +void thrower() { + printf("infunc..."); + throw(99); + printf("FAIL"); +} - void thrower() { - printf("infunc..."); - throw(99); - printf("FAIL"); - } +void somefunction() { + try { + thrower(); + } + catch (...) { + printf("done!*\n"); + } +} - void somefunction() { - try { - thrower(); - } catch(...) { - printf("done!*\n"); - } - } - - int main() { - somefunction(); - return 0; - } -
\ No newline at end of file +int main() { + somefunction(); + return 0; +} diff --git a/tests/core/test_zero_multiplication.in b/tests/core/test_zero_multiplication.in index 2be87594..bb6e7e12 100644 --- a/tests/core/test_zero_multiplication.in +++ b/tests/core/test_zero_multiplication.in @@ -1,14 +1,12 @@ +#include <stdio.h> +int main(int argc, char* argv[]) { + int one = argc; - #include <stdio.h> - int main(int argc, char * argv[]) { - int one = argc; - - printf("%d ", 0 * one); - printf("%d ", 0 * -one); - printf("%d ", -one * 0); - printf("%g ", 0.0 * one); - printf("%g ", 0.0 * -one); - printf("%g", -one * 0.0); - return 0; - } -
\ No newline at end of file + printf("%d ", 0 * one); + printf("%d ", 0 * -one); + printf("%d ", -one * 0); + printf("%g ", 0.0 * one); + printf("%g ", 0.0 * -one); + printf("%g", -one * 0.0); + return 0; +} diff --git a/tests/core/test_zerodiv.in b/tests/core/test_zerodiv.in index 991b6c1d..21430772 100644 --- a/tests/core/test_zerodiv.in +++ b/tests/core/test_zerodiv.in @@ -1,21 +1,18 @@ +#include <stdio.h> +int main(int argc, const char* argv[]) { + float f1 = 1.0f; + float f2 = 0.0f; + float f_zero = 0.0f; - #include <stdio.h> - int main(int argc, const char* argv[]) - { - float f1 = 1.0f; - float f2 = 0.0f; - float f_zero = 0.0f; + float f3 = 0.0f / f2; + float f4 = f2 / 0.0f; + float f5 = f2 / f2; + float f6 = f2 / f_zero; - float f3 = 0.0f / f2; - float f4 = f2 / 0.0f; - float f5 = f2 / f2; - float f6 = f2 / f_zero; + printf("f3: %f\n", f3); + printf("f4: %f\n", f4); + printf("f5: %f\n", f5); + printf("f6: %f\n", f6); - printf("f3: %f\n", f3); - printf("f4: %f\n", f4); - printf("f5: %f\n", f5); - printf("f6: %f\n", f6); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/gles2_conformance.cpp b/tests/gles2_conformance.cpp index 80539f7f..77681bf4 100644 --- a/tests/gles2_conformance.cpp +++ b/tests/gles2_conformance.cpp @@ -30,6 +30,16 @@ int main(int argc, char *argv[]) glShaderBinary(1, &vs, 0, 0, 0); assert(glGetError() != GL_NO_ERROR); + // Calling any of glGet() with null pointer should be detected and not crash. + // Note that native code can crash when passed a null pointer, and the GL spec does not say anything + // about this, so we spec that Emscripten GLES2 code should generate GL_INVALID_VALUE. + glGetBooleanv(GL_ACTIVE_TEXTURE, 0); + assert(glGetError() == GL_INVALID_VALUE); + glGetIntegerv(GL_ACTIVE_TEXTURE, 0); + assert(glGetError() == GL_INVALID_VALUE); + glGetFloatv(GL_ACTIVE_TEXTURE, 0); + assert(glGetError() == GL_INVALID_VALUE); + GLboolean b = GL_TRUE; GLint i = -1; GLfloat f = -1.f; @@ -44,18 +54,14 @@ int main(int argc, char *argv[]) assert(f == 0.f); // Currently testing that glGetIntegerv(GL_SHADER_BINARY_FORMATS) should be a no-op. - // The spec is somewhat vague here, equally as good could be to return GL_INVALID_ENUM here. - i = 123; - glGetIntegerv(GL_SHADER_BINARY_FORMATS, &i); + int formats[10] = { 123 }; + glGetIntegerv(GL_SHADER_BINARY_FORMATS, formats); assert(glGetError() == GL_NO_ERROR); - assert(i == 0); + assert(formats[0] == 123); - // Spec does not say what to report on the following, but since GL_SHADER_BINARY_FORMATS is supposed - // to return a a pointer to an array representing a list, the pointer can't be converted to bool or float, - // so report a GL_INVALID_ENUM. + // Converting enums to booleans or floats would be odd, so test that the following report a GL_INVALID_ENUM. glGetBooleanv(GL_SHADER_BINARY_FORMATS, &b); - assert(glGetError() == GL_INVALID_ENUM); - + assert(glGetError() == GL_INVALID_ENUM); glGetFloatv(GL_SHADER_BINARY_FORMATS, &f); assert(glGetError() == GL_INVALID_ENUM); diff --git a/tests/hello_image_sdl.c b/tests/hello_image_sdl.c new file mode 100644 index 00000000..449798bd --- /dev/null +++ b/tests/hello_image_sdl.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> +#include <unistd.h> + +int testImage(SDL_Surface* screen, const char* fileName) { + SDL_Surface *image = IMG_Load(fileName); + if (!image) + { + printf("IMG_Load: %s\n", IMG_GetError()); + return 0; + } + assert(image->format->BitsPerPixel == 32); + assert(image->format->BytesPerPixel == 4); + assert(image->pitch == 4*image->w); + int result = image->w; + + SDL_BlitSurface (image, NULL, screen, NULL); + SDL_FreeSurface (image); + + return result; +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + int result = 0; + + result |= testImage(screen, "screenshot.jpg"); // absolute path + assert(result != 0); + + SDL_Flip(screen); + + printf("you should see an image.\n"); + + SDL_Quit(); + + return 0; +} + diff --git a/tests/hello_world_exit.c b/tests/hello_world_exit.c new file mode 100644 index 00000000..febecc65 --- /dev/null +++ b/tests/hello_world_exit.c @@ -0,0 +1,9 @@ +#include<stdio.h> +#include<stdlib.h> + +int main() { + printf("hello, world!\n"); + fprintf(stderr, "hello, error stream!\n"); + exit(100); +} + diff --git a/tests/runner.py b/tests/runner.py index 8a5e1129..37e307e9 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -328,7 +328,10 @@ process(sys.argv[1]) os.makedirs(ret) return ret - def get_library(self, name, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=True, env_init={}, cache_name_extra='', native=False): + def get_library(self, name, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args='help', cache=True, env_init={}, cache_name_extra='', native=False): + if make_args == 'help': + make_args = ['-j', str(multiprocessing.cpu_count())] + build_dir = self.get_build_dir() output_dir = self.get_dir() diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 63e0041f..e38d80a9 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -14,6 +14,111 @@ DEFAULT_ARG = '4' TEST_REPS = 2 +CORE_BENCHMARKS = True # core benchmarks vs full regression suite + +class Benchmarker: + def __init__(self, name): + self.name = name + + def bench(self, args, output_parser=None): + self.times = [] + for i in range(TEST_REPS): + start = time.time() + output = self.run(args) + if not output_parser: + curr = time.time()-start + else: + curr = output_parser(output) + self.times.append(curr) + + def display(self, baseline=None): + if baseline == self: baseline = None + mean = sum(self.times)/len(self.times) + squared_times = map(lambda x: x*x, self.times) + mean_of_squared = sum(squared_times)/len(self.times) + std = math.sqrt(mean_of_squared - mean*mean) + sorted_times = self.times[:] + sorted_times.sort() + median = sum(sorted_times[len(sorted_times)/2 - 1:len(sorted_times)/2 + 1])/2 + + print ' %10s: mean: %4.3f (+-%4.3f) secs median: %4.3f range: %4.3f-%4.3f (noise: %4.3f%%) (%d runs)' % (self.name, mean, std, median, min(self.times), max(self.times), 100*std/mean, TEST_REPS), + + if baseline: + mean_baseline = sum(baseline.times)/len(baseline.times) + final = mean / mean_baseline + print ' Relative: %.2f X slower' % final + else: + print + +class NativeBenchmarker(Benchmarker): + def __init__(self, name, cc, cxx): + self.name = name + self.cc = cc + self.cxx = cxx + + def build(self, parent, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder): + self.parent = parent + if lib_builder: native_args += lib_builder(self.name, native=True, env_init={ 'CC': self.cc, 'CXX': self.cxx }) + if not native_exec: + compiler = self.cxx if filename.endswith('cpp') else self.cc + process = Popen([compiler, '-O2', '-fno-math-errno', filename, '-o', filename+'.native'] + shared_args + native_args, stdout=PIPE, stderr=parent.stderr_redirect) + output = process.communicate() + if process.returncode is not 0: + print >> sys.stderr, "Building native executable with command '%s' failed with a return code %d!" % (' '.join([compiler, '-O2', filename, '-o', filename+'.native']), process.returncode) + print "Output: " + output[0] + else: + print '(using clang)' + shutil.copyfile(native_exec, filename + '.native') + shutil.copymode(native_exec, filename + '.native') + self.filename = filename + + def run(self, args): + process = Popen([self.filename+'.native'] + args, stdout=PIPE, stderr=PIPE) + return process.communicate()[0] + +class JSBenchmarker(Benchmarker): + def __init__(self, name, engine, extra_args=[]): + self.name = name + self.engine = engine + self.extra_args = extra_args + + def build(self, parent, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder): + self.filename = filename + if lib_builder: emcc_args += lib_builder('js', native=False, env_init={}) + + open('hardcode.py', 'w').write(''' +def process(filename): + js = open(filename).read() + replaced = js.replace("run();", "run(%s.concat(Module[\\"arguments\\"]));") + assert js != replaced + open(filename, 'w').write(replaced) +import sys +process(sys.argv[1]) +''' % str(args[:-1]) # do not hardcode in the last argument, the default arg +) + + try_delete(filename + '.js') + output = Popen([PYTHON, EMCC, filename, #'-O3', + '-O2', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0', + '--memory-init-file', '0', '--js-transform', 'python hardcode.py', + '-s', 'TOTAL_MEMORY=128*1024*1024', + #'--closure', '1', + #'-g', + '-o', filename + '.js'] + shared_args + emcc_args + self.extra_args, stdout=PIPE, stderr=PIPE).communicate() + assert os.path.exists(filename + '.js'), 'Failed to compile file: ' + output[0] + + def run(self, args): + return run_js(self.filename + '.js', engine=self.engine, args=args, stderr=PIPE, full_output=True) + +# Benchmarkers +benchmarkers = [ + NativeBenchmarker('clang', CLANG_CC, CLANG), + NativeBenchmarker('gcc', 'gcc', 'g++'), + JSBenchmarker('sm-f32', SPIDERMONKEY_ENGINE, ['-s', 'PRECISE_F32=2']), + JSBenchmarker('sm', SPIDERMONKEY_ENGINE), + JSBenchmarker('v8', V8_ENGINE) +] + class benchmark(RunnerCore): save_dir = True @@ -49,47 +154,7 @@ class benchmark(RunnerCore): Building.COMPILER = CLANG Building.COMPILER_TEST_OPTS = [] - # Pick the JS engine to benchmark. If you specify one, it will be picked. For example, python tests/runner.py benchmark SPIDERMONKEY_ENGINE - global JS_ENGINE - JS_ENGINE = Building.JS_ENGINE_OVERRIDE if Building.JS_ENGINE_OVERRIDE is not None else JS_ENGINES[0] - print 'Benchmarking JS engine: %s' % JS_ENGINE - - def print_stats(self, times, native_times, last=False, reps=TEST_REPS): - if reps == 0: - print '(no reps)' - return - mean = sum(times)/len(times) - squared_times = map(lambda x: x*x, times) - mean_of_squared = sum(squared_times)/len(times) - std = math.sqrt(mean_of_squared - mean*mean) - sorted_times = times[:] - sorted_times.sort() - median = sum(sorted_times[len(sorted_times)/2 - 1:len(sorted_times)/2 + 1])/2 - - mean_native = sum(native_times)/len(native_times) - squared_native_times = map(lambda x: x*x, native_times) - mean_of_squared_native = sum(squared_native_times)/len(native_times) - std_native = math.sqrt(mean_of_squared_native - mean_native*mean_native) - sorted_native_times = native_times[:] - sorted_native_times.sort() - median_native = sum(sorted_native_times[len(sorted_native_times)/2 - 1:len(sorted_native_times)/2 + 1])/2 - - final = mean / mean_native - - if last: - norm = 0 - for i in range(len(times)): - norm += times[i]/native_times[i] - norm /= len(times) - print - print ' JavaScript: %.3f Native: %.3f Ratio: %.3f Normalized ratio: %.3f' % (mean, mean_native, final, norm) - return - - print - print ' JavaScript: mean: %.3f (+-%.3f) secs median: %.3f range: %.3f-%.3f (noise: %3.3f%%) (%d runs)' % (mean, std, median, min(times), max(times), 100*std/mean, reps) - print ' Native : mean: %.3f (+-%.3f) secs median: %.3f range: %.3f-%.3f (noise: %3.3f%%) JS is %.2f X slower' % (mean_native, std_native, median_native, min(native_times), max(native_times), 100*std_native/mean_native, final) - - def do_benchmark(self, name, src, expected_output='FAIL', args=[], emcc_args=[], native_args=[], shared_args=[], force_c=False, reps=TEST_REPS, native_exec=None, output_parser=None, args_processor=None): + def do_benchmark(self, name, src, expected_output='FAIL', args=[], emcc_args=[], native_args=[], shared_args=[], force_c=False, reps=TEST_REPS, native_exec=None, output_parser=None, args_processor=None, lib_builder=None): args = args or [DEFAULT_ARG] if args_processor: args = args_processor(args) @@ -98,68 +163,12 @@ class benchmark(RunnerCore): f = open(filename, 'w') f.write(src) f.close() - final_filename = os.path.join(dirname, name + '.js') - - open('hardcode.py', 'w').write(''' -def process(filename): - js = open(filename).read() - replaced = js.replace("run();", "run(%s.concat(Module[\\"arguments\\"]));") - assert js != replaced - open(filename, 'w').write(replaced) -import sys -process(sys.argv[1]) -''' % str(args[:-1]) # do not hardcode in the last argument, the default arg -) - - try_delete(final_filename) - output = Popen([PYTHON, EMCC, filename, #'-O3', - '-O2', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0', - '--memory-init-file', '0', '--js-transform', 'python hardcode.py', - '-s', 'TOTAL_MEMORY=128*1024*1024', - '--closure', '1', - #'-s', 'PRECISE_F32=1', - #'-g', - '-o', final_filename] + shared_args + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() - assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0] - # Run JS - times = [] - for i in range(reps): - start = time.time() - js_output = run_js(final_filename, engine=JS_ENGINE, args=args, stderr=PIPE, full_output=True) - - if i == 0 and 'uccessfully compiled asm.js code' in js_output: - if 'asm.js link error' not in js_output: - print "[%s was asm.js'ified]" % name - if not output_parser: - curr = time.time()-start - else: - curr = output_parser(js_output) - times.append(curr) - if i == 0: - # Sanity check on output - self.assertContained(expected_output, js_output) - - # Run natively - if not native_exec: - self.build_native(filename, shared_args + native_args) - else: - shutil.copyfile(native_exec, filename + '.native') - shutil.copymode(native_exec, filename + '.native') - native_times = [] - for i in range(reps): - start = time.time() - native_output = self.run_native(filename, args) - if i == 0: - # Sanity check on output - self.assertContained(expected_output, native_output) - if not output_parser: - curr = time.time()-start - else: - curr = output_parser(native_output) - native_times.append(curr) - - self.print_stats(times, native_times, reps=reps) + print + for b in benchmarkers: + b.build(self, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder) + b.bench(args, output_parser) + b.display(benchmarkers[0]) def test_primes(self): src = r''' @@ -402,9 +411,11 @@ process(sys.argv[1]) self.fasta('fasta_float', 'float') def test_fasta_double(self): + if CORE_BENCHMARKS: return self.fasta('fasta_double', 'double') def test_fasta_double_full(self): + if CORE_BENCHMARKS: return self.fasta('fasta_double_full', 'double', emcc_args=['-s', 'DOUBLE_MODE=1']) def test_skinning(self): @@ -412,10 +423,12 @@ process(sys.argv[1]) self.do_benchmark('skinning', src, 'blah=0.000000') def test_life(self): + if CORE_BENCHMARKS: return src = open(path_from_root('tests', 'life.c'), 'r').read() self.do_benchmark('life', src, '''--------------------------------''', shared_args=['-std=c99'], force_c=True) def test_linpack_double(self): + if CORE_BENCHMARKS: return def output_parser(output): return 100.0/float(re.search('Unrolled Double Precision +([\d\.]+) Mflops', output).group(1)) self.do_benchmark('linpack_double', open(path_from_root('tests', 'linpack.c')).read(), '''Unrolled Double Precision''', force_c=True, output_parser=output_parser) @@ -458,42 +471,29 @@ process(sys.argv[1]) def test_zzz_zlib(self): src = open(path_from_root('tests', 'zlib', 'benchmark.c'), 'r').read() - emcc_args = self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']) + \ - ['-I' + path_from_root('tests', 'zlib')] - native_args = self.get_library('zlib_native', os.path.join('libz.a'), make_args=['libz.a'], native=True) + \ - ['-I' + path_from_root('tests', 'zlib')] + def lib_builder(name, native, env_init): + return self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a'], native=native, cache_name_extra=name, env_init=env_init) self.do_benchmark('zlib', src, '''ok.''', - force_c=True, emcc_args=emcc_args, native_args=native_args) + force_c=True, shared_args=['-I' + path_from_root('tests', 'zlib')], lib_builder=lib_builder) def test_zzz_box2d(self): # Called thus so it runs late in the alphabetical cycle... it is long src = open(path_from_root('tests', 'box2d', 'Benchmark.cpp'), 'r').read() - - js_lib = self.get_library('box2d', [os.path.join('box2d.a')], configure=None) - native_lib = self.get_library('box2d_native', [os.path.join('box2d.a')], configure=None, native=True) - - emcc_args = js_lib + ['-I' + path_from_root('tests', 'box2d')] - native_args = native_lib + ['-I' + path_from_root('tests', 'box2d')] - - self.do_benchmark('box2d', src, 'frame averages', emcc_args=emcc_args, native_args=native_args) + def lib_builder(name, native, env_init): + return self.get_library('box2d', [os.path.join('box2d.a')], configure=None, native=native, cache_name_extra=name, env_init=env_init) + self.do_benchmark('box2d', src, 'frame averages', shared_args=['-I' + path_from_root('tests', 'box2d')], lib_builder=lib_builder) def test_zzz_bullet(self): # Called thus so it runs late in the alphabetical cycle... it is long src = open(path_from_root('tests', 'bullet', 'Demos', 'Benchmarks', 'BenchmarkDemo.cpp'), 'r').read() + \ open(path_from_root('tests', 'bullet', 'Demos', 'Benchmarks', 'main.cpp'), 'r').read() - js_lib = self.get_library('bullet', [os.path.join('src', '.libs', 'libBulletDynamics.a'), + def lib_builder(name, native, env_init): + return self.get_library('bullet', [os.path.join('src', '.libs', 'libBulletDynamics.a'), os.path.join('src', '.libs', 'libBulletCollision.a'), os.path.join('src', '.libs', 'libLinearMath.a')], - configure_args=['--disable-demos','--disable-dependency-tracking']) - native_lib = self.get_library('bullet_native', [os.path.join('src', '.libs', 'libBulletDynamics.a'), - os.path.join('src', '.libs', 'libBulletCollision.a'), - os.path.join('src', '.libs', 'libLinearMath.a')], - configure_args=['--disable-demos','--disable-dependency-tracking'], - native=True) - - emcc_args = js_lib + ['-I' + path_from_root('tests', 'bullet', 'src'), - '-I' + path_from_root('tests', 'bullet', 'Demos', 'Benchmarks'), - '-s', 'DEAD_FUNCTIONS=["__ZSt9terminatev"]'] - native_args = native_lib + ['-I' + path_from_root('tests', 'bullet', 'src'), - '-I' + path_from_root('tests', 'bullet', 'Demos', 'Benchmarks')] - - self.do_benchmark('bullet', src, '\nok.\n', emcc_args=emcc_args, native_args=native_args) + configure_args=['--disable-demos','--disable-dependency-tracking'], native=native, cache_name_extra=name, env_init=env_init) + + emcc_args = ['-s', 'DEAD_FUNCTIONS=["__ZSt9terminatev"]'] + + self.do_benchmark('bullet', src, '\nok.\n', emcc_args=emcc_args, shared_args=['-I' + path_from_root('tests', 'bullet', 'src'), + '-I' + path_from_root('tests', 'bullet', 'Demos', 'Benchmarks')], lib_builder=lib_builder) + diff --git a/tests/test_browser.py b/tests/test_browser.py index d0618af8..55bab05b 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1680,3 +1680,25 @@ keydown(100);keyup(100); // trigger the end open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000)) for extra_args in [[], ['--no-heap-copy']]: self.btest(path_from_root('tests', 'mmap_file.c'), expected='1', args=['--preload-file', 'data.dat'] + extra_args) + + def test_emrun_info(self): + result = subprocess.check_output([PYTHON, path_from_root('emrun'), '--system_info', '--browser_info']) + assert 'CPU' in result + assert 'Browser' in result + assert 'Traceback' not in result + + result = subprocess.check_output([PYTHON, path_from_root('emrun'), '--list_browsers']) + assert 'Traceback' not in result + + def test_emrun(self): + Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world_exit.c'), '--emrun', '-o', 'hello_world.html']).communicate() + outdir = os.getcwd() + # We cannot run emrun from the temp directory the suite will clean up afterwards, since the browser that is launched will have that directory as startup directory, + # and the browser will not close as part of the test, pinning down the cwd on Windows and it wouldn't be possible to delete it. Therefore switch away from that directory + # before launching. + os.chdir(path_from_root()) + process = subprocess.Popen([PYTHON, path_from_root('emrun'), '--timeout', '30', '--verbose', os.path.join(outdir, 'hello_world.html')], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = process.communicate() + assert process.returncode == 100 + assert 'hello, world!' in stdout + assert 'hello, error stream!' in stderr diff --git a/tests/test_core.py b/tests/test_core.py index 50167fe9..862beb8b 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -351,6 +351,9 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co } ''' self.do_run(src, '*4903566027370624, 153236438355333*') + + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read() assert 'goog.math.Long' not in code, 'i64 precise math should not have been included if not actually used' @@ -459,6 +462,8 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_float32_precise(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Settings.PRECISE_F32 = 1 test_path = path_from_root('tests', 'core', 'test_float32_precise') @@ -1086,36 +1091,48 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_longjmp(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_longjmp2(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp2') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_longjmp3(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp3') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_longjmp4(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp4') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_longjmp_funcptr(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp_funcptr') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_longjmp_repeat(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Settings.MAX_SETJMPS = 1 test_path = path_from_root('tests', 'core', 'test_longjmp_repeat') @@ -1124,6 +1141,8 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_longjmp_stacked(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp_stacked') src, output = (test_path + s for s in ('.in', '.out')) @@ -1131,12 +1150,16 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_longjmp_exc(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + test_path = path_from_root('tests', 'core', 'test_longjmp_exc') src, output = (test_path + s for s in ('.in', '.out')) self.do_run_from_file(src, output) def test_setjmp_many(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + src = r''' #include <stdio.h> #include <setjmp.h> @@ -1155,6 +1178,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_exceptions(self): if Settings.QUANTUM_SIZE == 1: return self.skip("we don't support libcxx in q1") if self.emcc_args is None: return self.skip('need emcc to add in libcxx properly') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.EXCEPTION_DEBUG = 1 @@ -1243,6 +1267,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_exception_2(self): if self.emcc_args is None: return self.skip('need emcc to add in libcxx properly') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.DISABLE_EXCEPTION_CATCHING = 0 test_path = path_from_root('tests', 'core', 'test_exception_2') @@ -1251,6 +1276,8 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_white_list_exception(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Settings.DISABLE_EXCEPTION_CATCHING = 2 Settings.EXCEPTION_CATCHING_WHITELIST = ["__Z12somefunctionv"] Settings.INLINING_LIMIT = 50 # otherwise it is inlined and not identified @@ -1265,6 +1292,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_uncaught_exception(self): if self.emcc_args is None: return self.skip('no libcxx inclusion without emcc') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.DISABLE_EXCEPTION_CATCHING = 0 @@ -1303,6 +1331,8 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run(src, 'success') def test_typed_exceptions(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Settings.DISABLE_EXCEPTION_CATCHING = 0 Settings.SAFE_HEAP = 0 # Throwing null will cause an ignorable null pointer access. src = open(path_from_root('tests', 'exceptions', 'typed.cpp'), 'r').read() @@ -1310,6 +1340,8 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run(src, expected) def test_multiexception(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Settings.DISABLE_EXCEPTION_CATCHING = 0 test_path = path_from_root('tests', 'core', 'test_multiexception') @@ -1319,6 +1351,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_std_exception(self): if self.emcc_args is None: return self.skip('requires emcc') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.DISABLE_EXCEPTION_CATCHING = 0 self.emcc_args += ['-s', 'SAFE_HEAP=0'] @@ -1844,12 +1877,9 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output, [], lambda x, err: x.replace('\n', '*')) - def test_float_h(self): - process = Popen([PYTHON, EMCC, path_from_root('tests', 'float+.c')], stdout=PIPE, stderr=PIPE) - process.communicate() - assert process.returncode is 0, 'float.h should agree with our system' - def test_llvm_used(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('pnacl kills llvm_used') + Building.LLVM_OPTS = 3 test_path = path_from_root('tests', 'core', 'test_llvm_used') @@ -1885,6 +1915,7 @@ def process(filename): def test_inlinejs(self): if not self.is_le32(): return self.skip('le32 needed for inline js') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') test_path = path_from_root('tests', 'core', 'test_inlinejs') src, output = (test_path + s for s in ('.in', '.out')) @@ -1897,6 +1928,7 @@ def process(filename): def test_inlinejs2(self): if not self.is_le32(): return self.skip('le32 needed for inline js') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') test_path = path_from_root('tests', 'core', 'test_inlinejs2') src, output = (test_path + s for s in ('.in', '.out')) @@ -2035,6 +2067,8 @@ def process(filename): ''', args=['34962', '26214', '35040']) def test_indirectbr(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS) test_path = path_from_root('tests', 'core', 'test_indirectbr') @@ -2043,6 +2077,8 @@ def process(filename): self.do_run_from_file(src, output) def test_indirectbr_many(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('blockaddr > 255 requires ta2') test_path = path_from_root('tests', 'core', 'test_indirectbr_many') @@ -2689,6 +2725,10 @@ The current type of b is: 9 self.do_run(main, 'supp: 54,2\nmain: 56\nsupp see: 543\nmain see: 76\nok.') def can_dlfcn(self): + if os.environ.get('EMCC_FAST_COMPILER') == '1': + self.skip('todo in fastcomp') + return False + if self.emcc_args and '--memory-init-file' in self.emcc_args: for i in range(len(self.emcc_args)): if self.emcc_args[i] == '--memory-init-file': @@ -3067,6 +3107,7 @@ def process(filename): def test_dlfcn_self(self): if Settings.USE_TYPED_ARRAYS == 1: return self.skip('Does not work with USE_TYPED_ARRAYS=1') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.DLOPEN_SUPPORT = 1 def post(filename): @@ -4016,6 +4057,8 @@ def process(filename): def test_utf32(self): if self.emcc_args is None: return self.skip('need libc for wcslen()') if not self.is_le32(): return self.skip('this test uses inline js, which requires le32') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') + self.do_run(open(path_from_root('tests', 'utf32.cpp')).read(), 'OK.') self.do_run(open(path_from_root('tests', 'utf32.cpp')).read(), 'OK.', args=['-fshort-wchar']) @@ -4550,6 +4593,7 @@ return malloc(size); def test_simd(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2') if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') test_path = path_from_root('tests', 'core', 'test_simd') src, output = (test_path + s for s in ('.in', '.out')) @@ -4558,6 +4602,7 @@ return malloc(size); def test_simd2(self): if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') test_path = path_from_root('tests', 'core', 'test_simd2') src, output = (test_path + s for s in ('.in', '.out')) @@ -4567,6 +4612,7 @@ return malloc(size); def test_simd3(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2') if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') test_path = path_from_root('tests', 'core', 'test_simd3') src, output = (test_path + s for s in ('.in', '.out')) @@ -4593,6 +4639,7 @@ return malloc(size); def test_lua(self): if self.emcc_args is None: return self.skip('requires emcc') if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: make this work') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') self.do_run('', 'hello lua world!\n17\n1\n2\n3\n4\n7', @@ -4610,6 +4657,7 @@ return malloc(size); def test_freetype(self): if self.emcc_args is None: return self.skip('requires emcc') if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: Figure out and try to fix') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') assert 'asm2g' in test_modes if self.run_name == 'asm2g': @@ -4742,7 +4790,7 @@ def process(filename): test() assert 'asm2g' in test_modes - if self.run_name == 'asm2g' and not use_cmake: + if self.run_name == 'asm2g' and not use_cmake and os.environ.get('EMCC_FAST_COMPILER') != '1': # Test forced alignment print >> sys.stderr, 'testing FORCE_ALIGNED_MEMORY' old = open('src.cpp.o.js').read() @@ -4755,6 +4803,7 @@ def process(filename): def test_poppler(self): if self.emcc_args is None: return self.skip('very slow, we only do this in emcc runs') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.CORRECT_OVERFLOWS = 1 Settings.CORRECT_SIGNS = 1 @@ -4969,6 +5018,14 @@ def process(filename): for name in glob.glob(path_from_root('tests', 'cases', '*.ll')): shortname = name.replace('.ll', '') if '' not in shortname: continue + if os.environ.get('EMCC_FAST_COMPILER') == '1' and os.path.basename(shortname) in [ + 'structparam', 'uadd_overflow_ta2', 'extendedprecision', 'issue_39', 'emptystruct', 'phinonexist', 'quotedlabel', 'oob_ta2', 'phientryimplicit', 'phiself', 'invokebitcast', # invalid ir + 'structphiparam', 'callwithstructural_ta2', 'callwithstructural64_ta2', 'structinparam', # pnacl limitations in ExpandStructRegs + '2xi40', # pnacl limitations in ExpandGetElementPtr + 'legalizer_ta2', '514_ta2', # pnacl limitation in not legalizing i104, i96, etc. + 'longjmp_tiny', 'longjmp_tiny_invoke', 'longjmp_tiny_phi', 'longjmp_tiny_phi2', 'indirectbrphi', 'ptrtoint_blockaddr', 'quoted', # current fastcomp limitations FIXME + 'sillyfuncast', 'sillyfuncast2', 'sillybitcast', # TODO very very soon XXX + ]: continue if '_ta2' in shortname and not Settings.USE_TYPED_ARRAYS == 2: print self.skip('case "%s" only relevant for ta2' % shortname) continue @@ -5371,6 +5428,7 @@ def process(filename): def test_embind(self): if self.emcc_args is None: return self.skip('requires emcc') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Building.COMPILER_TEST_OPTS += ['--bind'] src = r''' @@ -5393,6 +5451,7 @@ def process(filename): def test_embind_2(self): if self.emcc_args is None: return self.skip('requires emcc') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Building.COMPILER_TEST_OPTS += ['--bind', '--post-js', 'post.js'] open('post.js', 'w').write(''' Module.print('lerp ' + Module.lerp(1, 2, 0.66) + '.'); @@ -5413,6 +5472,7 @@ def process(filename): def test_scriptaclass(self): if self.emcc_args is None: return self.skip('requires emcc') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') Settings.EXPORT_BINDINGS = 1 @@ -5902,6 +5962,7 @@ def process(filename): def test_source_map(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays") + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') if NODE_JS not in JS_ENGINES: return self.skip('sourcemapper requires Node to run') if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g') @@ -5985,6 +6046,7 @@ def process(filename): if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays") if '-g4' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g4') if NODE_JS not in JS_ENGINES: return self.skip('sourcemapper requires Node to run') + if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp') src = ''' #include <stdio.h> diff --git a/tests/test_other.py b/tests/test_other.py index b10ae13b..46170856 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2150,3 +2150,8 @@ mergeInto(LibraryManager.library, { Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '--js-library', 'lib.js']).communicate() self.assertContained('hello, world!', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_float_h(self): + process = Popen([PYTHON, EMCC, path_from_root('tests', 'float+.c')], stdout=PIPE, stderr=PIPE) + out, err = process.communicate() + assert process.returncode is 0, 'float.h should agree with our system: ' + out + '\n\n\n' + err + diff --git a/tools/shared.py b/tools/shared.py index ca31d39c..443ff4c7 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -941,7 +941,7 @@ class Building: @staticmethod - def build_library(name, build_dir, output_dir, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None, native=False): + def build_library(name, build_dir, output_dir, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args='help', cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None, native=False): ''' Build a library into a .bc file. We build the .bc file once and cache it for all our tests. (We cache in memory since the test directory is destroyed and recreated for each test. Note that we cache separately for different compilers). @@ -949,6 +949,8 @@ class Building: if type(generated_libs) is not list: generated_libs = [generated_libs] if source_dir is None: source_dir = path_from_root('tests', name.replace('_native', '')) + if make_args == 'help': + make_args = ['-j', str(multiprocessing.cpu_count())] temp_dir = build_dir if copy_project: |