Apple Hardware Test (AHT)
Description
Apple computers ship with a pre-installed suite of hardware diagnostic tools, known as Apple Hardware Test (AHT). In principle you can start them by holding the d key while booting. Newer models support holding option d to load AHT over the internet. Refer to the official Apple documentation for details: Using AHT on Intel-based Macs, Mountain Lion, Mavericks and Yosemite. Apple redesigned the AHT, now called Apple Diagnostics, for Macs introduced after June 2013. Consult the reference codes to interpret the results.
If however, you reinstalled an older computer from scratch, the diagnostic tools might no longer be available. Unless you have the original disks that came with your computer, there seems to be no way to restore the AHT.
It happens that Apple provides disk images with AHT for most computers, but does not make the links publicly available. Various blogs and forums, mostly Riven by Five and MacForum.ro have gathered a list of download links. The rest were obtained by scraping http://download.info.apple.com/Apple_Hardware_Test/ for all the links of the form 0(18|22)-\d{4}-A.dmg.
Even though there's no guarantee that this list is correct or complete, some links can come in very handy to whoever is trying to debug hardware problems.
You can use the following terminal commands to determine the model and board ID of your computer:
sysctl hw.model | awk '{ print $2 }'
ioreg -l | awk -F\" '/board-id/ { print $4 }'
Download the AHT for your computer model and use the contents to restore the /System/Library/CoreServices/.diagnostics folder, then reboot while holding d to start the diagnostic tools. Alternatively you may try with a bootable USB stick, as described below. This is also the preferred way on OS X 10.11 or later, where the System Integrity Protection (SIP) no longer allows writing to system folders.
When trying to open an old dmg you may get the error 'legacy image should be converted'. To convert it to a newer format, open Disk Utility, in the menu Images click on Convert and select the dmg to convert and save it under a new name.
Note that there is no one-to-one correspondence between hardware model and AHT. For some models no hardware test could be found, while others seem to have multiple AHT. As the differences are not clear, feel free to try them out, to see which one works best for your hardware.
https://github.com/upekkha/AppleHardwareTest